#include <bits/stdc++.h>
using namespace std;
template <class T>
void show_2d_vector(const vector<vector<T>> &v) {
  for (auto v1 : v) {
    for (auto v2 : v1) {
      cout << v2 << " ";
    }
    cout << endl;
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  vector<bool> used(100005, false);
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= m; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i <= s.size(); i++) {
    used[s[i - 1]] = true;
    for (int j = 1; j <= t.size(); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= long long(1e9 + 7);
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
        dp[i][j] %= long long(1e9 + 7);
      }
    }
  }
  cout << dp[n][m] % long long(1e9 + 7) << endl;
  return 0;
}
