#include <bits/stdc++.h>
using namespace std;
const int MD = (int)1e9 + 7;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2>
void dbg(const T& fst, const T2&... rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2>
void amax(T& a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < (n); i++) cin >> s[i];
  for (int i = 0; i < (m); i++) cin >> t[i];
  vector<vector<long long> > dp(n + 2, vector<long long>(m + 2));
  dp[0][0] = 1;
  for (int i = 0; i < (n + 1); i++)
    for (int j = 0; j < (m + 1); j++) {
      if (i > 0 && j > 0 && s[i - 1] == t[j - 1]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] += (i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0);
      dp[i][j] -= ((i > 0 && j > 0) ? dp[i - 1][j - 1] : 0);
      dp[i][j] %= MD;
    }
  cout << dp[n][m] << "\n";
  return 0;
}
