#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < (N); i++) cin >> S[i];
  for (int i = 0; i < (M); i++) cin >> T[i];
  vector<vector<int>> dp(N + 1, vector<int>(M + 1)),
      sum(N + 2, vector<int>(M + 2));
  dp[0][0] = 1;
  for (int i = 0; i < (N + 1); i++)
    for (int j = 0; j < (M + 1); j++) {
      if (S[i - 1] == T[j - 1]) dp[i][j] = sum[i][j];
      sum[i + 1][j + 1] =
          (((sum[i + 1][j] + sum[i][j + 1]) % MOD - sum[i][j] + MOD) % MOD +
           dp[i][j]) %
          MOD;
    }
  cout << sum[N + 1][M + 1] << endl;
  return 0;
}
