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