#include <bits/stdc++.h>
using namespace std;
constexpr int M = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n], t[m];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  long long dp[2][n + 1];
  int cur = 0, prev = 1;
  fill(dp[prev], dp[prev] + n + 1, 1);
  dp[cur][0] = 1;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      dp[cur][i + 1] = dp[cur][i] + dp[prev][i + 1] - dp[prev][i];
      if (s[i] == t[j]) dp[cur][i + 1] += dp[prev][i];
      dp[cur][i + 1] %= M;
    }
    swap(cur, prev);
  }
  cout << dp[prev][n] << endl;
}
