#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 20;
const int MOD = 1e9 + 7;
long long fp(long long a, long long n, long long m = MOD) {
  long long res = 1;
  for (; n; n >>= 1, a = a * a % m)
    if (n & 1) res = res * a % m;
  return res;
}
int n, m;
int s[1111], t[1111];
int dp[1111][1111];
void work() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int j = 1; j <= m; j++) cin >> t[j];
  for (int i = 0; i <= n; i++) dp[i][0] = 1;
  for (int j = 0; j <= m; j++) dp[0][j] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
      if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
    }
  cout << dp[n][m] << endl;
}
int main() {
  work();
  return 0;
}
