#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
long long dp[2005][2005];
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N + 1), T(M + 1);
  for (long long i = 1; i <= N; i++) {
    cin >> S[i];
  }
  for (long long i = 1; i <= M; i++) {
    cin >> T[i];
  }
  for (long long i = 0; i <= N; i++) {
    dp[i][0] = 1;
  }
  for (long long i = 0; i <= M; i++) {
    dp[0][i] = 1;
  }
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) {
      if (S[i] == T[j]) {
        dp[i][j] =
            (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) + dp[i - 1][j - 1];
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      }
      dp[i][j] %= mod;
    }
  }
  cout << dp[N][M] << endl;
}
