#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[2005] = {};
  int t[2005] = {};
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &s[i]);
  for (int i = 0; i < (int)(m); i++) scanf("%d", &t[i]);
  long long int dp[2005][2005] = {};
  for (int i = 0; i < (int)(2005); i++) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  for (int y = 1; y <= m; y++) {
    for (int x = 1; x <= n; x++) {
      dp[y][x] = dp[y][x - 1] + dp[y - 1][x] - dp[y - 1][x - 1];
      if (s[x - 1] == t[y - 1]) {
        dp[y][x] += dp[y - 1][x - 1];
      }
      dp[y][x] %= 1000000007;
    }
  }
  printf("%lld\n", dp[m][n]);
  return 0;
}
