#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
int INF = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vi S(N), T(M);
  for (int i = 0; i < (int)N; i++) cin >> S[i];
  for (int i = 0; i < (int)M; i++) cin >> T[i];
  vvl dp(N + 1, vl(M + 1, 1));
  for (int i = 0; i < (int)N; i++) {
    for (int j = 0; j < (int)M; j++) {
      if (S[i] != T[j])
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % INF;
      else
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % INF;
    }
  }
  cout << dp[N][M] << endl;
}
