#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
long long r[2001][2001];
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(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 < n + 1; i++) {
    r[i][0] = 1;
  }
  for (int j = 0; j < n + 1; j++) {
    r[0][j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long add = 0;
      if (a[i - 1] == b[j - 1]) {
        add = r[i - 1][j - 1];
      }
      r[i][j] = add;
      r[i][j] += r[i - 1][j];
      r[i][j] += r[i][j - 1];
      r[i][j] -= r[i - 1][j - 1];
      r[i][j] = (r[i][j] % mod + mod) % mod;
    }
  }
  long long ans = r[n][m];
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
