#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
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;
}
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(M);
  for (int i = 0; i < (N); ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < (M); ++i) {
    cin >> T[i];
  }
  static long long dp[2003][2003] = {};
  dp[0][0] = 1;
  for (int i = 0; i < (N + 1); ++i) {
    dp[i][0] = 1;
  }
  for (int i = 0; i < (M + 1); ++i) {
    dp[0][i] = 1;
  }
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
      } else {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
      }
    }
  }
  cout << dp[N][M] % MOD << endl;
  return 0;
}
