#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
long long dp_memo[2010][2010];
long long sum_memo[2010][2010];
long long N, M;
vector<long long> S;
vector<long long> T;
long long dp(long long a, long long b);
long long sum(long long c, long long d);
long long dp(long long a, long long b) {
  if (a < 0 || b < 0) {
    return 0;
  }
  if (dp_memo[a][b] != -1) {
    return dp_memo[a][b];
  }
  if (S[a] != T[b]) {
    return 0;
  } else {
    return dp_memo[a][b] = (sum(a - 1, b - 1) + 1) % MOD;
  }
}
long long sum(long long c, long long d) {
  if (c < 0 || d < 0) {
    return 0;
  }
  if (sum_memo[c][d] != -1) {
    return sum_memo[c][d];
  }
  return sum_memo[c][d] = (MOD + sum(c - 1, d) + sum(c, d - 1) -
                           sum(c - 1, d - 1) + dp(c, d)) %
                          MOD;
}
int main() {
  cin >> N >> M;
  S.resize(N + 1);
  T.resize(M + 1);
  for (int i = 0; i < 2010; i++) {
    for (int j = 0; j < 2010; j++) {
      dp_memo[i][j] = -1;
      sum_memo[i][j] = -1;
    }
  }
  for (int i = 0; i < 2010; i++) {
    dp_memo[i][0] = 0;
    dp_memo[0][i] = 0;
  }
  dp_memo[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    cin >> S[i];
  }
  for (int j = 1; j <= M; j++) {
    cin >> T[j];
  }
  S[0] = INF;
  T[0] = INF;
  cout << sum(N, M) << endl;
  return 0;
}
