#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int S[2001], T[2001];
int dp[2001][2001];
int sum[2001][2001];
int main() {
  int N, M;
  cin >> N >> M;
  copy_n(istream_iterator<int>(cin), N, S);
  copy_n(istream_iterator<int>(cin), M, T);
  dp[0][0] = 1;
  for (int a = 1; a <= N; ++a) {
    for (int b = 1; b <= M; ++b) {
      if (S[a - 1] == T[b - 1])
        dp[a][b] = (sum[a - 1][b - 1] + 1) % mod;
      else
        dp[a][b] = 0;
      sum[a][b] =
          (sum[a - 1][b] - sum[a - 1][b - 1] + sum[a][b - 1]) % mod + dp[a][b];
      sum[a][b] %= mod;
    }
  }
  cout << sum[N][M] + 1 << '\n';
}
