#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;

ll dp[2123][2123];
ll sum[2123][2123];
int s[2123],t[2123];
signed main(){
    int N,M;
    cin>>N>>M;
    rep(i,N)cin>>s[i];
    rep(i,M)cin>>t[i];
    dp[0][0]=1;
    rep(i,N+1)
    {
        rep(j,M+1)
        {
            if(s[i]==t[j]){
                dp[i+1][j]+=dp[i][j]%mod;
                dp[i][j+1]+=dp[i][j]%mod;
            }else{
                dp[i+1][j]+=dp[i][j]%mod;
                dp[i][j+1]+=dp[i][j]%mod;
                dp[i+1][j+1]-=dp[i][j]%mod;

            }
        }
    }
    cout<<dp[N][M]<<endl;
 
}