#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
long long n, m;
long long dp[2010][2010];
long long s[2010], t[2010];
void init() {
  for (long long i = (0); i < (long long)(2010); i++) {
    for (long long j = (0); j < (long long)(2010); j++) dp[i][j] = 0;
  }
}
int main() {
  cin >> n >> m;
  for (long long i = (0); i < (long long)(n); i++) cin >> s[i];
  for (long long i = (0); i < (long long)(m); i++) cin >> t[i];
  init();
  for (long long i = (1); i < (long long)(n + 1); i++) {
    for (long long j = (1); j < (long long)(m + 1); j++) {
      if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
      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) % mod << endl;
  return 0;
}
