#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  int S[N], T[M];
  for (int i = 0; i < (N); ++i) cin >> S[i];
  for (int i = 0; i < (M); ++i) cin >> T[i];
  ll dp[N + 1][M + 1];
  ll sum[N + 2][M + 2];
  memset(dp, 0, sizeof(dp));
  memset(sum, 0, sizeof(sum));
  int ans = 0;
  dp[0][0] = 1;
  sum[1][1] = 1;
  for (int i = 0; i < (N + 1); ++i) {
    for (int j = 0; j < (M + 1); ++j) {
      if (i == 0 && j == 0) continue;
      if (i >= 1 && j >= 1 && S[i - 1] == T[j - 1])
        dp[i][j] = sum[i][j];
      else
        dp[i][j] = 0;
      sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i][j];
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << sum[N + 1][M + 1] << endl;
  return 0;
}
