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