#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long dp[2010][2010] = {0};
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (long long i = 0; i < (n); i++) cin >> s[i];
  for (long long i = 0; i < (m); i++) cin >> t[i];
  for (long long i = 0; i < (2005); i++) dp[i][0] = dp[0][i] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
      } else {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
