#include <bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
const int mod = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto &s : S) {
    cin >> s;
  }
  for (auto &t : T) {
    cin >> t;
  }
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    dp[i + 1][0] = 1;
  }
  for (int j = 0; j < M; ++j) {
    dp[0][j + 1] = 1;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] += dp[i][j];
      }
      dp[i + 1][j + 1] %= mod;
    }
  }
  printf("%lld\n", dp[N][M]);
  return 0;
}
