#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7;
string yn(bool f) { return f ? "Yes" : "No"; }
string YN(bool f) { return f ? "YES" : "NO"; }
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long N, M;
  vector<long long> S, T;
  static long long dp[2100][2100];
  static long long sum[2100][2100];
  long long con = 0;
  cin >> N >> M;
  S.resize(N);
  T.resize(M);
  for (long long i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (long long i = 0; i < M; i++) {
    cin >> T[i];
  }
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] += sum[i][j] + 1;
        dp[i + 1][j + 1] %= MOD;
      }
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << (sum[N][M] + 1) % MOD << "\n";
  return 0;
}
