#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int n, m;
long long f[2003][2003];
int s[10004], t[10004];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) scanf("%d", s + i);
  for (int i = 1; i <= m; ++i) scanf("%d", t + i);
  f[0][0] = 1;
  for (int i = 1; i <= n; ++i) f[0][i] = f[i][0] = 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) %= Mod;
      if (s[i] == t[j]) (f[i][j] += f[i - 1][j - 1]) %= Mod;
    }
  }
  cout << f[n][m] << endl;
  return 0;
}
