#include <bits/stdc++.h>
using namespace std;
vector<pair<string, pair<long long, long long> > > vec;
long long dp[2001][2001], sum[2001][2001];
int main() {
  long long N;
  long long M;
  scanf("%lld", &N);
  vector<long long> S(N - 1 + 1);
  scanf("%lld", &M);
  vector<long long> T(M - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    scanf("%lld", &S[i]);
  }
  for (int i = 0; i <= M - 1; i++) {
    scanf("%lld", &T[i]);
  }
  for (long long i = 0; i < N + 1; i++) {
    dp[i][0] = 0;
    sum[i][0] = 0;
  }
  for (long long i = 0; i < M + 1; i++) {
    dp[0][i] = 0;
    sum[0][i] = 0;
  }
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) {
      if (S[i - 1] == T[j - 1])
        dp[i][j] = (sum[i - 1][j - 1] + 1) % 1000000007;
      else
        dp[i][j] = 0;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) %
          1000000007;
    }
  }
  cout << sum[N][M] + 1 << endl;
  return 0;
}
