#include <bits/stdc++.h>
using namespace std;
long long MOD_N = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  int S[N];
  int T[M];
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  long long **counts = new long long *[N];
  long long **sums = new long long *[N];
  for (int i = 0; i < N; ++i) {
    counts[i] = new long long[M];
    sums[i] = new long long[M];
  }
  for (int i = 0; i < N; ++i) {
    counts[i][0] = (S[i] == T[0]) ? 1 : 0;
  }
  for (int j = 0; j < M; ++j) {
    counts[0][j] = (S[0] == T[j]) ? 1 : 0;
  }
  sums[0][0] = counts[0][0];
  for (int i = 1; i < N; ++i) {
    sums[i][0] = sums[i - 1][0] + counts[i][0];
  }
  for (int j = 1; j < M; ++j) {
    sums[0][j] = sums[0][j - 1] + counts[0][j];
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 1; j < M; ++j) {
      long long count, sum;
      if (S[i] == T[j]) {
        count = (sums[i - 1][j - 1] + 1) % MOD_N;
      } else {
        count = 0;
      }
      counts[i][j] = count;
      sum = sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1] + count;
      sums[i][j] = sum % MOD_N;
    }
  }
  int ans = (sums[N - 1][M - 1] + 1) % MOD_N;
  cout << ans << "\n";
  return 0;
}
