#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() {
  int right = 0;
  long long N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> 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); ++i) {
    for (int j = 0; j < (M); ++j) {
      if (i == 0 and j == 0) {
        dp[0][0] = 1;
        continue;
      } else if (i == 0) {
        if (S[i] == T[j]) {
          dp[i][j] = (dp[i][j - 1] + 1) % MOD;
        } else {
          dp[i][j] = (dp[i][j - 1] + 1 - 1) % MOD;
        }
        if (dp[i][j] < 0) dp[i][j] += MOD;
        continue;
      } else if (j == 0) {
        if (S[i] == T[j]) {
          dp[i][j] = (1 + dp[i - 1][j]) % MOD;
        } else {
          dp[i][j] = (1 + dp[i - 1][j] - 1) % MOD;
        }
        if (dp[i][j] < 0) dp[i][j] += MOD;
        continue;
      }
      if (S[i] == T[j]) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
      } else {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  cout << dp[N - 1][M - 1] % MOD << endl;
  return 0;
}
