#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> S(N);
    for (int &s: S)
        cin>>s;
    vector<int> T(M);
    for (int &t: T)
        cin>>t;

    vector<long long> A(N+1, 1LL);
    for (int i=0; i<M; i++)
    {
        vector<long long> P(N+1);
        P.swap(A);
        A[0] = 1LL;
        for (int j=0; j<N; j++)
            A[j+1] = (A[j] + P[j+1] - (S[j]==T[i] ? 0 : P[j]) + 1000000007LL)%1000000007LL;
    }
    cout<<A[N]<<endl;
}
