#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long dp[2005][2005];
long long sum[2005][2005];
long long s[2005];
long long t[2005];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) cin >> s[i + 1];
  for (int i = 0; i < m; i++) cin >> t[i + 1];
  sum[0][0] = dp[0][0] = 1;
  for (int i = 0; i <= n; i++) sum[i][0] = 1LL;
  for (int j = 0; j <= m; j++) sum[0][j] = 1LL;
  long long ans = 1LL;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1] % mod;
        ans += dp[i][j];
        ans %= mod;
      }
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % mod;
    }
  }
  cout << ans % mod << endl;
  return 0;
}
