#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int s[2005], t[2005];
long long dp[2005][2005], sum[2005][2005];
int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) s[i] = read();
  for (int i = 1; i <= m; i++) t[i] = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) dp[i][j] = sum[i - 1][j - 1] + 1;
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
      dp[i][j] %= p;
      sum[i][j] %= p;
    }
  }
  printf("%lld\n", (sum[n][m] + 1) % p);
  return 0;
}
