#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));
  vector<vector<int> > sums(n + 1, vector<int>(m + 1, 0));
  dp[0][0] = 1;
  sums[0][0] = 1;
  for (int i = 0; i < m + 1; i++) sums[0][i] = 1;
  for (int i = 0; i < n + 1; i++) sums[i][0] = 1;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = 1;
        dp[i][j] += (sums[i - 1][j - 1]);
      }
      sums[i][j] +=
          (sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1] + dp[i][j]);
      sums[i][j] %= mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
