#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = int(2e9);
const long long LINF = long long(2e9) * long long(2e9);
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> T(M);
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  long long p = 1000000007;
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1, 0));
  dp[0][0] = 1;
  long long ans = 0;
  for (int i = 0; i < N + 1; i++) dp[i][0] = 1;
  for (int i = 0; i < M + 1; i++) dp[0][i] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < M + 1; j++) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
        dp[i][j] %= p;
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
        dp[i][j] %= p;
      }
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
