#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long dp[2005][2005];
long long sum[2005][2005];
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];
  if (s[0] == t[0]) {
    dp[0][0] = 1;
    sum[0][0] = 1;
  } else {
    dp[0][0] = 0;
    sum[0][0] = 0;
  }
  for (int i = 1; i < N; i++) {
    if (s[i] == t[0]) {
      dp[i][0] = 1;
    } else {
      dp[i][0] = 0;
    }
    sum[i][0] = sum[i - 1][0] + dp[i][0];
  }
  for (int j = 1; j < M; j++) {
    if (s[0] == t[j]) {
      dp[0][j] = 1;
    } else {
      dp[0][j] = 0;
    }
    sum[0][j] = sum[0][j - 1] + dp[0][j];
  }
  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;
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] = dp[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      sum[i][j] %= MOD;
    }
  }
  cout << sum[N - 1][M - 1] + 1 << endl;
  return 0;
}
