#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T& x) {
  cout << x << endl;
}
template <class T, class... A>
void print(const T& first, const A&... rest) {
  cout << first << " ";
  print(rest...);
}
struct PreMain {
  PreMain() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} premain;
int dp[2001][2001];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (int(i) = 0; (i) < (int)(N); ++(i)) cin >> S[i];
  for (int(j) = 0; (j) < (int)(M); ++(j)) cin >> T[j];
  dp[0][0] = 1;
  for (int(i) = 0; (i) < (int)(N + 1); ++(i)) dp[i][0] = 1;
  for (int(j) = 0; (j) < (int)(M + 1); ++(j)) dp[0][j] = 1;
  for (int(i) = 1; (i) < (int)(N + 1); ++(i))
    for (int(j) = 1; (j) < (int)(M + 1); ++(j)) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % (1000000007);
      } else {
        dp[i][j] =
            (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % (1000000007);
      }
    }
  print(dp[N][M]);
  return 0;
}
