#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200000;
const long long INF = 1001001001;
const long long MOD = 1000000007;
long long N, M, ans = 0, tmp = 0;
vector<long long> S, T;
vector<vector<long long>> dp;
signed main() {
  cin >> N >> M;
  dp.resize(2100);
  for (long long i = 0; i < 2100; i++) {
    dp[i].resize(2100, 0);
  }
  for (long long i = 0; i < N; i++) {
    long long a;
    cin >> a;
    S.push_back(a);
  }
  for (long long i = 0; i < M; i++) {
    long long a;
    cin >> a;
    T.push_back(a);
  }
  dp[0][0] = 1;
  for (long long i = 0; i <= N; i++) {
    for (long long j = 0; j <= M; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1])
        dp[i][j] += dp[i - 1][j - 1];
      if (i - 1 >= 0) dp[i][j] += dp[i - 1][j];
      if (j - 1 >= 0) dp[i][j] += dp[i][j - 1];
      if (i - 1 >= 0 && j - 1 >= 0) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
