#include <bits/stdc++.h>
using namespace std;
int dp[2005][2005];
int a[2005];
int b[2005];
int mod = 1e9 + 7;
int ncs(int n, int m) {
  if (n == 0 || m == 0) return 0;
  if (dp[n][m] != -1) return dp[n][m] % mod;
  if (a[n - 1] == b[m - 1])
    return dp[n][m] = (1 + ncs(n - 1, m) + ncs(n, m - 1)) % mod;
  else
    return dp[n][m] = (ncs(n - 1, m) + ncs(n, m - 1) - ncs(n - 1, m - 1)) % mod;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < m; j++) cin >> b[j];
  cout << 1 + ncs(n, m) << '\n';
  return 0;
}
