from functools import reduce

NNN = 10 ** 9 + 7


def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s)


if __name__ == '__main__':
    main() from functools import reduce NNN = 10 ** 9 + 7 NNN 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s) main int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a N, M = [int(a) for a in input().split()] N [int(a) for a in input().split()] M int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a S = [int(a) for a in input().split()] S [int(a) for a in input().split()] int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a T = [int(a) for a in input().split()] T [int(a) for a in input().split()] table = [0] * M table [0] * M [0] 0 M for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

     si reversed(S) reversed S c = 0 c 0 for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

     i reversed(range(M)) reversed range(M) range M prev_score = table[i] prev_score table[i] table i if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
             T[i] == si T[i] T i si table[i] = (table[i] + c + 1) % NNN table[i] table i (table[i] + c + 1) % NNN table[i] + c + 1 table[i] + c table[i] table i c 1 NNN c = (c + prev_score) % NNN c (c + prev_score) % NNN c + prev_score c prev_score NNN s = 1 s 1 for a in table:
        s = (s + a) % NNN
     a table s = (s + a) % NNN s (s + a) % NNN s + a s a NNN print(s) print s if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s) def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s) main NNN = 10 ** 9 + 7 10 ** 9 + 7 NNN
from functools import reduce

NNN = 10 ** 9 + 7


def main():
    N, M = [int(a) for a in input().split()]
    S = [int(a) for a in input().split()]
    T = [int(a) for a in input().split()]

    table = [0] * M

    for si in reversed(S):
        c = 0
        for i in reversed(range(M)):
            prev_score = table[i]
            if T[i] == si:
                table[i] = (table[i] + c + 1) % NNN
            c = (c + prev_score) % NNN

    s = 1
    for a in table:
        s = (s + a) % NNN
    print(s)


if __name__ == '__main__':
    main()
