#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int MOD = 1e9 + 7;
int n, m;
int s[2005], t[2005], f[2005][2005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 1; i <= m; i++) scanf("%d", &t[i]);
  for (int i = 0; i <= n; i++) f[i][0] = 1;
  for (int i = 0; i <= m; i++) f[0][i] = 1;
  for (int i = 1; i <= n; i++)
    for (int 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] += f[i - 1][j - 1];
      f[i][j] %= MOD;
    }
  printf("%d\n", f[n][m]);
  return 0;
}
