#include <bits/stdc++.h>
using namespace std;
static const int MAX = 1e6;
static const int NIL = -1;
static const long long INF = 1 << 21;
static const long long MOD = 1e9 + 7;
bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
  return arg1.first > arg2.first;
}
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> T(M);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int j = 0; j < M; j++) {
    cin >> T.at(j);
  }
  long long dp[N + 5][M + 5];
  long long sum[N + 5][M + 5];
  for (int i = 0; i < N + 5; i++) {
    for (int j = 0; j < M + 5; j++) {
      dp[i][j] = 0;
      sum[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  sum[1][1] = 1;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      if (i == 0 && j == 0) continue;
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        dp[i][j] = sum[i][j] % MOD;
      }
      sum[i + 1][j + 1] = (sum[i + 1][j] % MOD) + (sum[i][j + 1] % MOD) -
                          (sum[i][j] % MOD) + (dp[i][j] % MOD);
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << sum[N + 1][M + 1] % MOD << endl;
  return (0);
}
