#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T>
void printv(const vector<T>& s) {
  for (int i = 0; i < (int)(s.size()); ++i) {
    cout << s[i];
    if (i == (int)(s.size()) - 1)
      cout << endl;
    else
      cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll 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<ll>> dp(n + 1, vector<ll>(m + 1, 0));
  vector<vector<ll>> cnt(n + 1, vector<ll>(m + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = cnt[i][j] + 1;
      }
      cnt[i + 1][j + 1] =
          cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + dp[i + 1][j + 1];
      cnt[i + 1][j + 1] %= MOD;
    }
  }
  cout << cnt[n][m] + 1 << endl;
}
