#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr long long int SIZE = 2010;
long long int dp[SIZE][SIZE];
long long int sum[SIZE][SIZE];
void solve() {
  long long int N, M;
  cin >> N >> M;
  vector<long long int> s(N);
  for (auto &x : s) {
    cin >> x;
  }
  vector<long long int> t(M);
  for (auto &x : t) {
    cin >> x;
  }
  for (long long int i = 0; i <= N; i++) {
    sum[i][0] = 1;
  }
  for (long long int i = 0; i <= M; i++) {
    sum[0][i] = 1;
  }
  long long int ret = 1;
  for (long long int i = 0; i < N; i++) {
    for (long long int j = 0; j < M; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1] + 1;
        ret += dp[i][j];
      }
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j] + MOD) %
          MOD;
    }
  }
  cout << ret % MOD << endl;
}
signed main() {
  solve();
  return 0;
}
