import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1)


if __name__ == '__main__':
    main() import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = float('INF') INF float('INF') float 'INF' sys.setrecursionlimit(10 ** 5) sys.setrecursionlimit sys setrecursionlimit 10 ** 5 10 5 def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1) main n, m = list(map(int, readline().split())) n list(map(int, readline().split())) list 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] * (m + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [0] * (m + 1) [0] 0 m + 1 m 1 dp = [[0] * (m + 1) for _ in range(n + 1)] dp [[0] * (m + 1) for _ in range(n + 1)] for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

     i val_s enumerate(s, 1) enumerate s 1 for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

     j val_t enumerate(t, 1) enumerate t 1 num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] num dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] dp[i - 1][j] + dp[i][j - 1] dp[i - 1][j] [i - 1] dp i - 1 i 1 j dp[i][j - 1] [i] dp i j - 1 j 1 dp[i - 1][j - 1] [i - 1] dp i - 1 i 1 j - 1 j 1 if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
             val_s == val_t val_s val_t num += dp[i - 1][j - 1] + 1 num dp[i - 1][j - 1] + 1 dp[i - 1][j - 1] [i - 1] dp i - 1 i 1 j - 1 j 1 1 num %= MOD num MOD dp[i][j] = num dp[i][j] [i] dp i j num print(dp[n][m] + 1) print dp[n][m] + 1 dp[n][m] [n] dp n m 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main INF = float('INF') float('INF') INF readline = sys.stdin.readline sys.stdin.readline readline MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1) def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1) main
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    s = list(map(int, readline().split()))
    t = list(map(int, readline().split()))

    dp = [[0] * (m + 1) for _ in range(n + 1)]

    for i, val_s in enumerate(s, 1):
        for j, val_t in enumerate(t, 1):
            num = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
            if val_s == val_t:
                num += dp[i - 1][j - 1] + 1
            num %= MOD
            dp[i][j] = num

    print(dp[n][m] + 1)


if __name__ == '__main__':
    main()
