#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  const long long q = 1000000007;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (long long i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> t.at(i);
  }
  vector<vector<long long> > dp(n, vector<long long>(m));
  vector<vector<long long> > sum(n, vector<long long>(m));
  if (s[0] == t[0]) {
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
  }
  sum[0][0] = dp[0][0] + 1;
  for (long long j = 1; j < m; j++) {
    if (s[0] == t[j]) {
      dp[0][j] = 1;
      sum[0][j] = dp[0][j] + sum[0][j - 1];
    } else {
      dp[0][j] = 0;
      sum[0][j] = dp[0][j] + sum[0][j - 1];
    }
  }
  for (long long i = 1; i < n; i++) {
    if (s[i] == t[0]) {
      dp[i][0] = 1;
      sum[i][0] = dp[i][0] + sum[i - 1][0];
    } else {
      dp[i][0] = 0;
      sum[i][0] = dp[i][0] + sum[i - 1][0];
    }
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1];
        dp[i][j] %= q;
      } else {
        dp[i][j] = 0;
      }
      sum[i][j] = dp[i][j] + sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
      sum[i][j] %= q;
    }
  }
  printf("%lld", sum[n - 1][m - 1]);
  return 0;
}
