#include <bits/stdc++.h>
using namespace std;
const int mn = 2e3 + 10;
const long long mod = 1e9 + 7;
int s[mn], t[mn];
long long dp[mn][mn];
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", s + i), dp[i][0] = 1;
  for (i = 1; i <= m; i++) scanf("%d", t + i), dp[0][i] = 1;
  dp[0][0] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  printf("%lld", dp[n][m]);
}
