#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  map<int, vector<int>> ms, mt;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (ms.count(s[i]) == 0) {
      vector<int> v;
      ms[s[i]] = v;
    }
    ms[s[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
    if (mt.count(t[i]) == 0) {
      vector<int> v;
      mt[t[i]] = v;
    }
    mt[t[i]].push_back(i);
  }
  long long def = 1;
  for (int i = 0; i < 9; i++) def *= 10;
  def += 7;
  vector<vector<long long>> dp(n, vector<long long>(m, 0));
  if (s[0] == t[0]) {
    dp[0][0] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (i != 0) {
      dp[i][0] = dp[i - 1][0];
      if (s[i] == t[0]) {
        dp[i][0]++;
      }
    }
    for (int j = 1; j < m; j++) {
      dp[i][j] = dp[i][j - 1];
      if (ms.count(t[j]) == 0) continue;
      auto tempv = ms[t[j]];
      for (int k = 0; k < tempv.size(); k++) {
        int tempi = tempv[k];
        if (tempi > i) continue;
        if (tempi != 0) {
          dp[i][j] += dp[tempi - 1][j - 1];
        }
        dp[i][j]++;
        dp[i][j] %= def;
      }
    }
  }
  cout << dp[n - 1][m - 1] + 1 << endl;
  return 0;
}
