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