#include <bits/stdc++.h>
using namespace std;
long long dp[2006][2006];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> S(n);
  vector<int> T(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 < (2006); i++) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  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]) % 1000000007;
      } else {
        dp[i + 1][j + 1] =
            (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % 1000000007;
      }
    }
  }
  cout << (dp[n][m]) << endl;
  return 0;
}
