#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < (n); ++i) cin >> s[i];
  for (int j = 0; j < (m); ++j) cin >> t[j];
  vector<vector<long long> > data(n, vector<long long>(m, 0));
  vector<vector<long long> > sum(n, vector<long long>(m, 0));
  if (s[0] == t[0]) {
    data[0][0] = 1;
  } else {
    data[0][0] = 0;
  }
  sum[0][0] = data[0][0];
  for (int i = (1); i < (n); i++) {
    if (s[i] == t[0]) {
      data[i][0] = 1;
    } else {
      data[i][0] = 0;
    }
    sum[i][0] = (sum[i - 1][0] + data[i][0]) % MOD;
  }
  for (int j = (1); j < (m); j++) {
    if (t[j] == s[0]) {
      data[0][j] = 1;
    } else {
      data[0][j] = 0;
    }
    sum[0][j] = (sum[0][j - 1] + data[0][j]) % MOD;
  }
  for (int i = (1); i < (n); i++) {
    for (int j = (1); j < (m); j++) {
      if (s[i] == t[j]) {
        data[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      } else {
        data[i][j] = 0;
      }
      sum[i][j] =
          (sum[i - 1][j] - sum[i - 1][j - 1] + sum[i][j - 1] + data[i][j]) %
          MOD;
    }
  }
  cout << (sum[n - 1][m - 1] + 1) % MOD << endl;
  return 0;
}
