#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, S[2000], T[2000], MOD = 1000000007;
  static long long DP[2010][2010] = {};
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        DP[i + 1][j + 1] = DP[i + 1][j] + DP[i][j + 1] + 1;
      } else {
        DP[i + 1][j + 1] = DP[i + 1][j] + DP[i][j + 1] - DP[i][j];
      }
      DP[i + 1][j + 1] = DP[i + 1][j + 1] % MOD;
    }
  }
  cout << (DP[N][M] + 1) % MOD;
}
