#include <bits/stdc++.h>
using namespace std;
int s[2005], t[2005];
long long f[2005][2005];
long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> t[i];
  f[0][0] = 1;
  for (int i = 1; i <= n; i++) f[i][0] = 1;
  for (int i = 1; i <= m; i++) f[0][i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1]) % mod;
      if (s[i] == t[j]) f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;
    }
  cout << f[n][m] << endl;
  return 0;
}
