#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
template<ll Mod>
struct mod_int {
  static const ll mod = Mod;
  ll val;
  mod_int(long long sig = 0):val(sig%mod) { sig%=mod; if(sig<0) sig+=mod; }

  constexpr mod_int operator- () const {return val?mod-val:0;}
  constexpr mod_int &operator+=(const mod_int &that) { if ((val += that.val) >= MOD) val -= MOD; return *this; }
  constexpr mod_int &operator-=(const mod_int &that) { if ((val += MOD - that.val) >= MOD) val -= MOD; return *this; }
  constexpr mod_int &operator*=(const mod_int &that) { val = (unsigned long long)val * that.val % MOD; return *this; }
  constexpr mod_int &operator/=(const mod_int &that) { return *this *= that.inverse(); }

  constexpr mod_int operator+(const mod_int &that) const { return mod_int(*this) += that; }
  constexpr mod_int operator-(const mod_int &that) const { return mod_int(*this) -= that; }
  constexpr mod_int operator*(const mod_int &that) const { return mod_int(*this) *= that; }
  constexpr mod_int operator/(const mod_int &that) const { return mod_int(*this) /= that; }
  constexpr bool operator==(const mod_int &that) const noexcept{
    return this->val == that.val;
  }
  constexpr bool operator!=(const mod_int &that) const noexcept{
    return this->val != that.val;
  }
  friend constexpr ostream& operator << (ostream &os, const mod_int &x) noexcept {
    return os << x.val;
  }
  friend constexpr istream& operator >> (istream &is, mod_int& x) noexcept {
    return is >> x.val;
  }
  friend constexpr mod_int modpow(const mod_int &a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
  mod_int inverse() const {
    long long a = val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    return mod_int(u);
  }
};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  vi s(n),t(m);
  cin >> s >> t;
  using mint = mod_int<MOD>;
  VV<mint> dp(n+10,V<mint>(m+10,0));
  dp[0][0] = 1;
  REP(i,n+1)REP(j,m+1){
    dp[i+1][j] += dp[i][j];
    dp[i][j+1] += dp[i][j];
    dp[i+1][j+1] -= dp[i][j];
    if(s[i]==t[j]) dp[i+1][j+1] += dp[i][j];
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 32000