#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long dp[2019][2019];
int main() {
  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 a = 1, b = 1;
  for (int i = 0; i < (n); i++) {
    if (s[i] == t[0]) a++;
    dp[i][0] = a;
    dp[i][0] %= MOD;
  }
  for (int i = 0; i < (m); i++) {
    if (s[0] == t[i]) b++;
    dp[0][i] = b;
    dp[0][i] %= MOD;
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      dp[i + 1][j + 1] += dp[i][j + 1] % MOD;
      dp[i + 1][j + 1] += dp[i + 1][j] % MOD;
      dp[i + 1][j + 1] -= dp[i][j] % MOD;
      if (s[i + 1] == t[j + 1]) dp[i + 1][j + 1] += dp[i][j] % MOD;
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[n - 1][m - 1] % MOD << endl;
  return 0;
}
