#include <bits/stdc++.h>
using namespace std;
const int mode = 1e9 + 7;
int dp[2001][2001];
int main() {
  int n, m;
  cin >> n >> m;
  int a[2001], b[2001];
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int j = 1; j <= m; j++) scanf("%d", &b[j]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (a[i] == b[j]) dp[i][j] += dp[i - 1][j - 1] + 1;
      if (dp[i][j] > 0)
        dp[i][j] = dp[i][j] % mode;
      else
        dp[i][j] += mode;
    }
  }
  cout << dp[n][m] + 1 << endl;
  return 0;
}
