#include <bits/stdc++.h>
using namespace std;
int64_t dp[2001][2001];
int A[2000];
int B[2000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> B[i];
  }
  for (int i = 0; i <= 2000; i++) {
    dp[i][0] = dp[0][i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (A[i - 1] != B[j - 1]) {
        dp[i][j] =
            (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
      } else {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      }
    }
  }
  int64_t ans = 0;
  cout << dp[n][m];
  return 0;
}
