/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
*/
//
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
void solve()
{
    int n;
    cin>>n;
    vector<int> v(n);
    int cnt=0;
    f(i,n)
    {
        cin>>v[i];
    }
    int k,x;
    cin>>k>>x;
    vector<int> a;
    f(i,n)
    {
        a.pb((v[i]^x)-v[i]);
        if(a.back()>=0)
        {
            cnt++;
        }
    }
    sort(all(a),greater<int>());
    if(cnt>=k)
    {
        int i=0;
        ll sum=0;
        while(i<n&&a[i]>=0)
        {
            sum=sum+a[i];
            i++;
        }
        if(cnt%k&&cnt%2)
        {
            if(i>=0)
            {
                if(abs(v[i+1])<abs(v[i]))
                {
                    sum=sum-a[i+1];
                }
                else
                {
                    sum=sum+a[i];
                }
                sum=accumulate(all(v),sum);
                cout<<sum<<endl;
            }
            else
            {
                sum=sum-a[i+1];
                sum=accumulate(all(v),sum);
                cout<<sum<<endl;
            }
        }
        else
        {
            sum=accumulate(all(v),sum);
            cout<<sum<<endl;
        }
    }
    else
    {
        
    }
}
long long CommomSubsequencesCount(vector<int> &s, vector<int> &t)
{
    long long n1 = (int)s.size();
    ll n2 = (int)t.size();
    ll dp[n1+1][n2+1];
    
    for (ll i = 0; i <= n1; i++) {
        for (ll j = 0; j <= n2; j++) {
            dp[i][j] = 0;
        }
    }
    
    // for each character of S
    for (ll i = 1; i <= n1; i++) {
        
        // for each charcater in T
        for (ll j = 1; j <= n2; j++) {
            
            // if character are same in both
            // the string
            if (s[i - 1] == t[j - 1])
                dp[i][j] = (1 + dp[i][j - 1]%inf + dp[i - 1][j]%inf)%inf;
            else
                dp[i][j] = (dp[i][j - 1]%inf + dp[i - 1][j]%inf -dp[i - 1][j - 1]%inf+inf)%inf;
        }
    }
    
    return dp[n1][n2];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    int n,m;
    cin>>n>>m;
    vector<int> v1(n),v2(m);
    f(i,n)
    {
        cin>>v1[i];
    }
    f(j,m)
    {
        cin>>v2[j];
    }
    ll ans=CommomSubsequencesCount(v1,v2);
    cout<<(ans+1)%inf<<endl;
}


Measured memory_bytes: 31616