#include <bits/stdc++.h>
using namespace std;
const long long MAX_LEN = 2002;
const long long MOD = 1000000007;
long long dp[MAX_LEN][MAX_LEN];
long long GetCommomSubsequencesCount(long long s[], long long t[], long long n,
                                     long long m) {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j]) % MOD;
      } else {
        dp[i][j] =
            ((dp[i][j - 1] + dp[i - 1][j]) % MOD - dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  return dp[n][m] % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long s[n], t[m];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> t[i];
  }
  long long ans = GetCommomSubsequencesCount(s, t, n, m) % MOD;
  cout << ans + 1 << '\n';
  cout.flush();
}
