#include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 60;
const long double EPS = 1e-10;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const long long MOD = 1000000007;
template <class T>
inline void amax(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
inline void amin(T &a, const T &b) {
  if (a > b) a = b;
}
long long binary(long long key, vector<long long> &a) {
  long long ok = a.size();
  long long dame = -1;
  while (abs(ok - dame) > 1) {
    long long mid = (ok + dame) / 2;
    if (a[mid] <= key)
      ok = mid;
    else
      dame = mid;
  }
  return ok;
}
long long n;
long long m;
long long k;
long long l;
long long temp;
long long x, y;
long long H, W;
char c;
long long ddy, ddx;
signed main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  vector<long long> s(n);
  vector<long long> t(m);
  for (long long i = (long long)0; i < (long long)n; i++) scanf("%lld", &s[i]);
  for (long long i = (long long)0; i < (long long)m; i++) scanf("%lld", &t[i]);
  vector<vector<long long> > dp(n + 5, vector<long long>(m + 5, 0));
  dp[0][0] = 1;
  vector<vector<long long> > sum(n + 5, vector<long long>(m + 5, 0));
  for (long long i = (long long)0; i < (long long)n + 5; i++) sum[i][0] = 1;
  for (long long i = (long long)0; i < (long long)m + 5; i++) sum[0][i] = 1;
  long long ans = 1;
  for (long long i = (long long)0; i < (long long)n; i++)
    for (long long j = (long long)0; j < (long long)m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (sum[i][j]) % MOD;
        ans = (ans + dp[i + 1][j + 1]) % MOD;
      }
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1]) % MOD;
    }
  printf("%lld\n", ans);
}
