#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
int N, M;
ll dp[2222][2222], sum[2222][2222];
int main() {
  cin >> N >> M;
  vector<int> S(N), T(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  dp[0][0] = 1;
  for (int j = 0; j <= M; j++) {
    sum[0][j] = 1;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) dp[i + 1][j + 1] = sum[i][j];
    }
    ll now = 0;
    for (int j = 0; j <= M; j++) {
      now += dp[i + 1][j] % mod;
      now %= mod;
      sum[i + 1][j] = (sum[i][j] + now) % mod;
    }
  }
  cout << sum[N][M] << endl;
}
