#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 5000 + 5;
long long n, m, a[N], b[N], dp[N][N];
long long solve(long long x, long long y) {
  if (x > n || y > n) return 0;
  if (dp[x][y] != -1) return dp[x][y];
  dp[x][y] = 0;
  if (a[x] == b[y]) dp[x][y] += solve(x + 1, y + 1) + 1;
  dp[x][y] += solve(x + 1, y);
  dp[x][y] += solve(x, y + 1);
  dp[x][y] -= solve(x + 1, y + 1);
  return dp[x][y];
}
signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= m; i++) scanf("%lld", &b[i]);
  cout << (solve(1, 1) + 1) % mod;
}
