#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int &x : a) cin >> x;
  for (int &x : b) cin >> x;
  const int mod = (int)1e9 + 7;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
  for (int i = n; i >= 0; --i)
    for (int j = m; j >= 0; --j) {
      long long &res = dp[i][j] = 0;
      if (i == n || j == m)
        res = 1;
      else {
        if (a[i] == b[j]) res += dp[i + 1][j + 1];
        res += dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1];
        res %= mod;
      }
    }
  cout << dp[0][0];
  return 0;
}
