#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
long long MOD = 1000000007;
long long N, M;
const long long MAX_NM = 2000;
int second[MAX_NM], T[MAX_NM];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> second[i];
  for (int j = 0; j < M; j++) cin >> T[j];
  long long dp[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++) dp[i][0] = 1;
  for (int j = 0; j < M + 1; j++) dp[0][j] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[i + 1][j + 1] = dp[i + 1][j] - dp[i][j] + dp[i][j + 1];
      if (second[i] == T[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
