#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}
long long dp[2020][2020];
long long sum[2020][2020];
long long ret;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(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];
  }
  for (long long i = 0; i < (long long)2020; i++) {
    sum[i][0] = 1;
    sum[0][i] = 1;
  }
  long long res = 1;
  for (long long x = 0; x < (long long)N; x++) {
    for (long long y = 0; y < (long long)M; y++) {
      if (S[x] == T[y]) {
        dp[x + 1][y + 1] = sum[x][y] % MOD;
        ret += dp[x + 1][y + 1];
      }
      long long tmp =
          sum[x][y + 1] + sum[x + 1][y] + MOD - sum[x][y] + dp[x + 1][y + 1];
      sum[x + 1][y + 1] = tmp % MOD;
    }
  }
  cout << ret % MOD << endl;
}
