#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include <bits/stdc++.h>
using namespace std;
#define fast()                 ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tc()                 int t; cin>>t; while(t--)
#define pr(n)             cout<<n<<"\n"
#define in(n)                 int n; cin>>n
#define mem(a, b)             memset(a, (b), sizeof(a))
#define FOR(i, j, k, in)     for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in)     for (int i=j ; i>=k ; i-=in)
#define fr(i, n)             FOR(i, 0, n, 1)
#define rfr(i, n)             RFOR(i, j, 0, 1)
#define all(cont)             cont.begin(), cont.end()
#define rall(cont)             cont.end(), cont.begin()
#define gcd(a,b)              __gcd(a,b)
#define mp                     make_pair
#define pb                     push_back
#define X                     first
#define Y                     second
#define sz                     size
#define clr                 clear
#define len                 length
#define inf                 (ll)1e9
#define eps                 1e-9
#define pi                     3.1415926535897932384626433832795
#define h                     1000000007
#define gc                     getchar//_unlocked
#define pc                     putchar//_unlocked
const double                 PI=acos(-1.0);
#define pl(a, n)             for (ll i = 0; i < n; i++) cout << a[i] << ' ' ; br
#define pv(v)                 for (auto itv = v.begin(); itv != v.end(); itv++) cout << *itv << ' ' ; br
#define ps(s)                 for (auto its = s.begin(); its != s.end(); its++) cout << *its << ' '; br
#define pmp(m)                 for (auto itm = m.begin(); itm != m.end(); itm++) cout << (*itm).ff << ' ' << (*itm).ss << endl;
#define pmm(m)                 for (auto itm = m.begin(); itm != m.end(); itm++) cout << (*itm).ff << ' ' << (*itm).ss << endl;
#define p2(a, b)             cout << a << ' ' << b; br
#define p3(a, b, c)         cout << a << ' ' << b << ' ' << c; br
#define p4(a, b, c, d)         cout << a << ' ' << b << ' ' << c << ' ' << d; br
#define sum(a, n, s)         ll s = 0; for (ll i = 0; i < n; i++) s += a[i];
#define br                     cout << endl;
#define il(arr,n)             vll arr(n,0); fr(i,n) {cin>>arr[i];}
typedef long long int         ll;
typedef long double         ld;
typedef pair<ll,ll>         pii;
typedef vector<pii>         vpii;
typedef vector<ll>             vll;
typedef vector<int>         vi;
typedef vector<vi>             vvi;
typedef map<int,int>         mii;
typedef set<int>             seti;
typedef multiset<int>         mulset;


clock_t time_p=clock();
void amit()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

#ifdef AMIT
#define dbg(...) { cerr<<"[ "; __amit__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.X<<","<<x.Y<<")";
}

template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}

template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}

template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}

template <typename Arg1>
void __amit__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}

template <typename Arg1, typename... Args>
void __amit__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __amit__(names.substr(1+(int)name.size()), args...);
}

#else
    #define dbg(args...)
#endif

const ll INF = 0xFFFFFFFFFFFFFFFL;

ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF)
{return uniform_int_distribution<ll>(l,r)(rng);}

class CMP
{public:
bool operator()(pii a , pii b) //For min priority_queue .
{    return ! ( a.X < b.X || a.X==b.X && a.Y <= b.Y);   }};

void add( map<ll,ll> &m, ll x,ll cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<ll,ll> &m, ll x,ll cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const pii &a,const pii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const ll mod = 1000000007L;
const ll MXN = 10000L;
//priority_queue < pii , vector < pii > , CMP > pq;// min priority_queue .
//----------------------------------------------------------------------------------------
ll CommomSubsequencesCount(string s, string t) 
{ 
    int n1 = s.size(); 
    int n2 = t.size(); 
    ll dp[n1+1][n2+1]; 
  
    for (int i = 0; i <= n1; i++) { 
        for (int j = 0; j <= n2; j++) { 
            dp[i][j] = 0; 
        } 
    } 
  
    for (int i = 1; i <= n1; i++) { 
        for (int j = 1; j <= n2; j++) { 
            if (s[i - 1] == t[j - 1])  
                dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j])%h;             
            else 
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] -  
                                        dp[i - 1][j - 1])%h;             
        } 
    } 
  
    return dp[n1][n2]; 
}

signed main()
{
    fast();
    //cout<<std::fixed<<std::setprecision(35);
    in(n); in(m);
    il(s,n);
    il(t,n);
    cout<<(CommomSubsequencesCount(s,t)+1)%h<<endl;


    amit();
    return 0;
}