#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
signed main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < (n); i++) cin >> s[i];
  for (long long i = 0; i < (m); i++) cin >> t[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (m); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % 1000000007;
      } else {
        dp[i + 1][j + 1] =
            (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % 1000000007;
      }
    }
  }
  cout << dp[n][m] << endl;
}
