#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Max(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool Min(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
inline int Read(void) {
  int res = 0, flag = 1;
  char c;
  while (c = getchar(), c < 48 || c > 57)
    if (c == '-') flag = 0;
  do res = (res << 1) + (res << 3) + (c ^ 48);
  while (c = getchar(), c >= 48 && c <= 57);
  return flag ? res : -res;
}
const int N = 2e3 + 5, M = 1e6 + 5, mod = 1e9 + 7;
const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int n, m, dp[N][N], S[N], T[N];
int dfs(int x, int y) {
  if (~dp[x][y]) return dp[x][y];
  if (x == 0 || y == 0) return 1;
  int res = 0;
  if (S[x] == T[y]) res = dfs(x - 1, y - 1);
  res = (res + dfs(x - 1, y) + dfs(x, y - 1) - dfs(x - 1, y - 1)) % mod;
  dp[x][y] = res;
  return dp[x][y];
}
int main(void) {
  memset(dp, -1, sizeof dp);
  n = Read(), m = Read();
  for (register int i = (1), i_end_ = (n); i <= i_end_; ++i) S[i] = Read();
  for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) T[i] = Read();
  printf("%d", dfs(n, m));
  return 0;
}
