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