#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 + 3e3;
const long long oo = 1 + 1e18, mod = 7 + 1e9;
int n, m, a[MAXN], b[MAXN];
long long f[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i][0] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    f[0][i] = 1;
  }
  f[0][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] * 1ll * (a[i] != b[j])) %
          mod;
    }
  }
  cout << f[n][m];
  return 0;
}
