/*
>>> In The Name Of GOD

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


bool cmp_pair_F_2(pair <int,int> x, pair <int,int> y)
{
    return x.F>y.F;
}
bool cmp_pair_S_2(pair <int,int> x, pair <int,int> y)
{
    return x.S>y.S;
}
bool cmp_pair_S_1(pair <int,int> x, pair <int,int> y)
{
    return x.S<y.S;
}

bool cmp(int x, int y)
{
	return x>y;
}

const ll N=2003, mod=1e9+7, base=100003;//,  base2=100019;
ll n,m;
ll a[N],b[N];

ll h1[N],h2[N], power[base];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //int i,j;
	cin >> n >> m;
	power[0]=1;
	for (int i=1;i<base;i++)
        power[i]=(power[i-1]*base)%mod;
	for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        h1[i]=(h1[i-1]*base+a[i])%mod;
    }
    for (int i=1;i<=m;i++)
    {
        cin >> b[i];
        h2[i]=(h2[i-1]*base+b[i])%mod;
    }
    vector <ll> v1[N],v2[N];
    for (int d=1;d<=n;d++)
    {
        for (int i=1;i<=n-d+1;i++)
        {
            int j=i+d-1;
            ll h=(h1[j]-h1[i-1]*power[d]);
            v1[d].pb(h);
        }
        sort(all(v1[d]));
    }
    for (int d=1;d<=m;d++)
    {
        for (int i=1;i<=m-d+1;i++)
        {
            int j=i+d-1;
            ll h=(h2[j]-h2[i-1]*power[d]);
            v2[d].pb(h);
        }
        sort(all(v2[d]));
    }

    //d2.resize(unique(all(d2))-d2.begin());
    ll c=1;
    for (int d=1;d<=min(n,m);d++)
    {
        vector <ll> d1=v1[d];
        d1.resize(unique(all(d1))-d1.begin());
        for (auto i:d1)
        {
            ll x=ub(all(v1[d]), i)-lb(all(v1[d]),i);
            ll y=ub(all(v2[d]), i)-lb(all(v2[d]),i);
            cout << d << ' ' << x << ' ' << y << endl;
            c= (c+x*y)%mod;
        }
    }
    cout << c;
    return 0;
}
*/
/**
>>> In The Name Of GOD
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


/*bool c_p_F2(pii x, pii y)
{
    return x.F>y.F;
}
bool c_p_S2(pii x, pii y)
{
    return x.S>y.S;
}
bool c_p_S1(pii x, pii y)
{
    return x.S<y.S;
}*/

bool cmp(int x, int y)
{
	return x>y;
}

const int N=2003;
const ll mod=1e9+7;
int a[N],b[N];
ll dp[N][N];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++)
        cin >> a[i];
    for (int i=1;i<=m;i++)
        cin >> b[i];
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            if (a[i]==b[j])dp[i][j]=(1+dp[i-1][j-1])%mod;
            dp[i][j]=(dp[i][j] + dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]+mod)%mod;
        }
    cout << (dp[n][m]+1+mod)%mod;
    return 0;
}


Measured memory_bytes: 31616