#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 2e3 + 10;
const long long p = 1e9 + 7;
long long a[maxn], b[maxn];
long long dp[maxn][maxn], sum[maxn][maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (long long i = 0; i <= m; i++) {
    sum[0][i] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= m; j++) {
      sum[i][j] = sum[i - 1][j] + (j == 0 ? 0 : sum[i][j - 1]) -
                  (j == 0 ? 0 : sum[i - 1][j - 1]);
      if (a[i] == b[j])
        sum[i][j] = (sum[i][j] + (j == 0 ? 0 : sum[i - 1][j - 1])) % p;
      sum[i][j] %= p;
    }
  }
  cout << sum[n][m] << "\n";
  return 0;
}
