#include <bits/stdc++.h>
using namespace std;
constexpr int Inf = 1000000000;
constexpr long long INF = 9 * 1e18;
constexpr long long MOD = 1000000007;
const double PI = 3.1415926535897;
template <typename T>
T Pow(T a, T b) {
  T ret = 1;
  for (int i = 0; i < b; i++) {
    ret *= a;
  }
  return ret;
}
long long dp[2020][2020];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  vector<int> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T.at(i);
  }
  for (int i = 0; i < 2020; i++) {
    for (int j = 0; j < 2020; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i) == T.at(j)) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
        dp[i + 1][j + 1] %= MOD;
      }
    }
  }
  cout << dp[N][M] % MOD << endl;
}
