#include <bits/stdc++.h>
using namespace std;
int a[2001], b[2001];
long long dp[2001][2001];
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == b[1]) dp[i][1] = 1;
    dp[i][1] += dp[i - 1][1];
  }
  for (i = 1; i <= m; i++) {
    if (b[i] == a[1]) dp[1][i] = 1;
    dp[1][i] += dp[1][i - 1];
  }
  for (i = 2; i <= n; i++)
    for (j = 2; j <= m; j++) {
      if (a[i] == b[j])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % 1000000007;
      dp[i][j] = (dp[i][j] + dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) %
                 1000000007;
    }
  printf("%lld", (dp[n][m] + 1) % 1000000007);
  return 0;
}
