#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 5;
const long long M = 2e3 + 5;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
long long n, m, s[N], t[M];
long long f[N][M];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> t[i];
  }
  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];
      if (s[i] == t[j]) f[i][j] += 1 + f[i - 1][j - 1];
      f[i][j] %= MOD;
    }
  }
  long long ans = f[n][m] + 1;
  cout << ans << '\n';
  return 0;
}
