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