import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
s = list(map(int, readline().split()))
t = list(map(int, readline().split()))
dp = [[0] * (n + 1) for _ in range(m + 1)]
cumsum = [[0] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i, tt in enumerate(t):
    i += 1
    for j, ss in enumerate(s):
        j += 1
        if tt == ss:
            dp[i][j] = cumsum[i - 1][j - 1] + 1
            dp[i][j] %= mod
        else:
            dp[i][j] = 0
        cumsum[i][j] = cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j]
        cumsum[i][j] %= mod
print(cumsum[-1][-1] + 1) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 n, m = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m s = list(map(int, readline().split())) s list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split t = list(map(int, readline().split())) t list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split [0] * (n + 1) for _ in range(m + 1) for _ in range(m + 1) _ range(m + 1) range m + 1 m 1 for _ in range(m + 1) [0] * (n + 1) [0] 0 n + 1 n 1 dp = [[0] * (n + 1) for _ in range(m + 1)] dp [[0] * (n + 1) for _ in range(m + 1)] [0] * (n + 1) for _ in range(m + 1) for _ in range(m + 1) _ range(m + 1) range m + 1 m 1 for _ in range(m + 1) [0] * (n + 1) [0] 0 n + 1 n 1 cumsum = [[0] * (n + 1) for _ in range(m + 1)] cumsum [[0] * (n + 1) for _ in range(m + 1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 for i, tt in enumerate(t):
    i += 1
    for j, ss in enumerate(s):
        j += 1
        if tt == ss:
            dp[i][j] = cumsum[i - 1][j - 1] + 1
            dp[i][j] %= mod
        else:
            dp[i][j] = 0
        cumsum[i][j] = cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j]
        cumsum[i][j] %= mod i tt enumerate(t) enumerate t i += 1 i 1 for j, ss in enumerate(s):
        j += 1
        if tt == ss:
            dp[i][j] = cumsum[i - 1][j - 1] + 1
            dp[i][j] %= mod
        else:
            dp[i][j] = 0
        cumsum[i][j] = cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j]
        cumsum[i][j] %= mod j ss enumerate(s) enumerate s j += 1 j 1 if tt == ss:
            dp[i][j] = cumsum[i - 1][j - 1] + 1
            dp[i][j] %= mod
        else:
            dp[i][j] = 0
         tt == ss tt ss dp[i][j] = cumsum[i - 1][j - 1] + 1 dp[i][j] [i] dp i j cumsum[i - 1][j - 1] + 1 cumsum[i - 1][j - 1] [i - 1] cumsum i - 1 i 1 j - 1 j 1 1 dp[i][j] %= mod dp[i][j] [i] dp i j mod dp[i][j] = 0 dp[i][j] [i] dp i j 0 cumsum[i][j] = cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j] cumsum[i][j] [i] cumsum i j cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j] cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] cumsum[i - 1][j] + cumsum[i][j - 1] cumsum[i - 1][j] [i - 1] cumsum i - 1 i 1 j cumsum[i][j - 1] [i] cumsum i j - 1 j 1 cumsum[i - 1][j - 1] [i - 1] cumsum i - 1 i 1 j - 1 j 1 dp[i][j] [i] dp i j cumsum[i][j] %= mod cumsum[i][j] [i] cumsum i j mod print(cumsum[-1][-1] + 1) print cumsum[-1][-1] + 1 cumsum[-1][-1] [-1] cumsum -1 -1 1 readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines s = list(map(int, readline().split())) list(map(int, readline().split())) s mod = 10 ** 9 + 7 10 ** 9 + 7 mod cumsum = [[0] * (n + 1) for _ in range(m + 1)] [[0] * (n + 1) for _ in range(m + 1)] cumsum dp = [[0] * (n + 1) for _ in range(m + 1)] [[0] * (n + 1) for _ in range(m + 1)] dp i += 1 1 i n, m = map(int, readline().split()) map(int, readline().split()) n m = map(int, readline().split()) map(int, readline().split()) m j += 1 1 j t = list(map(int, readline().split())) list(map(int, readline().split())) t readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline read = sys.stdin.buffer.read sys.stdin.buffer.read read
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
s = list(map(int, readline().split()))
t = list(map(int, readline().split()))
dp = [[0] * (n + 1) for _ in range(m + 1)]
cumsum = [[0] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i, tt in enumerate(t):
    i += 1
    for j, ss in enumerate(s):
        j += 1
        if tt == ss:
            dp[i][j] = cumsum[i - 1][j - 1] + 1
            dp[i][j] %= mod
        else:
            dp[i][j] = 0
        cumsum[i][j] = cumsum[i - 1][j] + cumsum[i][j - 1] - cumsum[i - 1][j - 1] + dp[i][j]
        cumsum[i][j] %= mod
print(cumsum[-1][-1] + 1)
