#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int s[2005], t[2005];
long long dp[2005][2005];
long long solve(int x, int y) {
  if (x < 0 || y < 0) return 0LL;
  if (dp[x][y] != -1) return dp[x][y];
  long long val = 0;
  if (s[x] != t[y])
    val = solve(x - 1, y) + solve(x, y - 1) - solve(x - 1, y - 1);
  else
    val = 1LL + solve(x - 1, y) + solve(x, y - 1);
  val %= MOD;
  return dp[x][y] = val;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  for (int i = 0; i < m; i++) scanf("%d", &t[i]);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", (solve(n - 1, m - 1) + 1) % MOD);
}
