#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2000 + 50;
const long long mod = 1000000007;
long long s[maxn], t[maxn], dp[maxn][maxn];
long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) s[i] = read();
  for (int i = 1; i <= m; i++) t[i] = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  cout << dp[n][m] + 1 << endl;
  return 0;
}
