#include <bits/stdc++.h>
using namespace std;
template <typename T>
void getMin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void getMax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
vector<T> getVector(const int n) {
  return vector<T>(n);
}
template <typename T>
vector<T> getVector(const int n, const T a) {
  return vector<T>(n, a);
}
template <typename T>
vector<T> getEmptyVector() {
  return vector<T>();
}
template <typename T>
void appendAll(vector<T> &a, vector<T> b) {
  a.insert(a.end(), b.begin(), b.end());
}
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const long long MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 28;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1), T(M + 1);
  for (int i = (1); i <= ((int)N); i++) cin >> S[i];
  for (int i = (1); i <= ((int)M); i++) cin >> T[i];
  vector<vector<int> > dp(N + 1, vector<int>(M + 1));
  dp[0][0] = 1;
  for (int i = (1); i <= ((int)N); i++) dp[i][0] = 1;
  for (int j = (1); j <= ((int)M); j++) dp[0][j] = 1;
  for (int i = (1); i <= ((int)N); i++) {
    for (int j = (1); j <= ((int)M); j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
      if (S[i] == T[j]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
