#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
void add(T &a, T b) {
  a = (a + b) % MOD;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1));
  vector<vector<long long>> sum(N + 1, vector<long long>(M + 1));
  sum[N][M] = 1;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) {
      if (S[i] == T[j]) add(dp[i + 1][j + 1], sum[i][j] + 1);
      add(sum[i + 1][j + 1],
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1]);
    }
  cout << sum[N][M] << endl;
  return 0;
}
