#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long maxn = 2e3 + 5;
const long long mo_num = 1e9 + 7;
long long n, m, a[maxn], b[maxn], ans;
long long f[maxn][maxn];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) cin >> b[i];
  for (long long i = 1; i <= n; i++) f[i][0] = 1;
  for (long long i = 1; i <= m; i++) f[0][i] = 1;
  f[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1]) % mo_num;
      if (a[i] == b[j]) f[i][j] = (f[i - 1][j - 1] + f[i][j]) % mo_num;
    }
  }
  cout << f[n][m];
  return 0;
}
