#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int max_n = 1011;
int main() {
  int n, a[max_n], m, b[max_n];
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
  }
  int dp[max_n][max_n];
  for (int i = 0; i <= max(n, m); ++i) {
    dp[i][0] = 1;
    dp[0][i] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int q = 1; q <= m; ++q) {
      dp[i][q] = 0;
      if (i) dp[i][q] += dp[i - 1][q];
      if (q) dp[i][q] += dp[i][q - 1];
      if (i && q && a[i - 1] != b[q - 1]) dp[i][q] -= dp[i - 1][q - 1];
      if (dp[i][q] < 0) dp[i][q] += mod;
      dp[i][q] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
