#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
long long N, M, S[2010], T[2010];
long long dp[2010][2010], SUM[2010][2010];
void solve() {
  for (long long i = (0); i < (N + 1); ++i) {
    SUM[i][0] = 1;
    SUM[0][i] = 1;
  }
  for (long long i = (1); i < (N + 1); ++i) {
    for (long long j = (1); j < (M + 1); ++j) {
      if (S[i] == T[j]) {
        dp[i][j] = SUM[i - 1][j - 1];
      }
      SUM[i][j] = SUM[i][j - 1] + SUM[i - 1][j] - SUM[i - 1][j - 1] + dp[i][j];
      SUM[i][j] %= MOD;
    }
  }
  cout << SUM[N][M] << endl;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (long long i = (1); i < (N + 1); ++i) {
    cin >> S[i];
  }
  for (long long i = (1); i < (M + 1); ++i) {
    cin >> T[i];
  }
  solve();
  return 0;
}
