#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = (int)0; i < (int)n; ++i) cin >> s[i];
  for (int i = (int)0; i < (int)m; ++i) cin >> t[i];
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
  vector<vector<ll>> sum(n + 1, vector<ll>(m + 1));
  dp[0][0] = 1;
  sum[1][1] = 1;
  for (int i = (int)0; i < (int)n; ++i) {
    for (int j = (int)0; j < (int)m; ++j) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] += sum[i][j] + 1;
      }
      sum[i + 1][j + 1] =
          sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= mod;
    }
  }
  cout << (sum[n][m] + 1) % mod << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
