#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline bool inside(int y, int x, int H, int W) {
  return (y >= 0 && x >= 0 && y < H && x < W);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp0[2005][2005];
ll dp1[2005][2005];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vi s(n), t(m);
  for (int i = (int)(0); i < (int)(n); ++i) cin >> s[i];
  for (int i = (int)(0); i < (int)(m); ++i) cin >> t[i];
  for (int i = (int)(0); i < (int)(n + 1); ++i)
    for (int j = (int)(0); j < (int)(m + 1); ++j) {
      (dp0[i + 1][j] += dp0[i][j]) %= MOD;
      (dp1[i][j] += dp0[i][j]) %= MOD;
      (dp1[i][j + 1] += dp1[i][j]) %= MOD;
      if (s[i] == t[j]) (dp0[i + j][j + 1] += dp1[i][j]) %= MOD;
    }
  ll ans = dp1[n][m] % MOD;
  cout << ans << endl;
}
