#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  vector<int> s, t;
  vector<vector<long long> > dp;
  cin >> n >> m;
  s.assign(n, 0);
  t.assign(m, 0);
  dp.assign(n + 1, vector<long long>(m + 1));
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    dp[i + 1][0] = 1;
  }
  for (int j = 0; j < m; j++) {
    cin >> t[j];
    dp[0][j + 1] = 1;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long tmp = 0;
      if (s[i - 1] == t[j - 1]) {
        tmp = dp[i - 1][j - 1];
      }
      dp[i][j] = tmp + dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] << endl;
}
