#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int dp[2019][2019];
long long int ans[2020][2020];
long long int S[2019];
long long int T[2019];
signed main(void) {
  long long int N, M;
  cin >> N >> M;
  for (long long int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (long long int i = 0; i < M; i++) {
    cin >> T[i];
  }
  for (long long int i = 0; i < N; i++) {
    for (long long int j = 0; j < M; j++) {
      dp[i][j] = 0;
    }
  }
  for (long long int i = 0; i <= N; i++) {
    for (long long int j = 0; j <= M; j++) {
      ans[i][j] = 0;
      if (i == 0 || j == 0) {
        ans[i][j] = 1;
      }
    }
  }
  for (long long int j = 0; j < M; j++) {
    for (long long int i = 0; i < N; i++) {
      if (S[i] == T[j]) {
        dp[i][j] = ans[i][j];
        dp[i][j] %= mod;
      } else {
        dp[i][j] = 0;
      }
      ans[i + 1][j + 1] = dp[i][j] + ans[i][j + 1] + ans[i + 1][j] - ans[i][j];
      ans[i + 1][j + 1] %= mod;
    }
  }
  cout << ans[N][M] % mod << endl;
}
