#include <bits/stdc++.h>
using namespace std;
int64_t MOD = 1e9 + 7;
int64_t power(int64_t a, int64_t n) {
  if (a == 0) return 0;
  if (n == 0) return 1;
  int64_t res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = res * a % MOD;
    a = a * a % MOD;
    n /= 2;
  }
  return res;
}
int64_t inv(int64_t a) { return power(a, MOD - 2); }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(2010, 0), T(2010, 0);
  for (int i = 1; i <= (int)(N); i++) cin >> S[i];
  for (int i = 1; i <= (int)(M); i++) cin >> T[i];
  vector<vector<int64_t>> dp(2010, vector<int64_t>(2010, 0));
  vector<vector<int64_t>> sum(2010, vector<int64_t>(2010, 1));
  dp[0][0] = 1;
  for (int i = 1; i <= (int)(N); i++) {
    for (int j = 1; j <= (int)(M); j++) {
      if (S[i] == T[j]) dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  cout << (sum[N][M] - 1) * inv(2) % MOD + 1 << endl;
}
