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