#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[n + 1], dp[n + 1][m + 1];
  vector<long long> cur(1e5 + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int i = 0; i <= m; i++) dp[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 1;
    cur.assign(1e5 + 1, 0);
    for (int j = 1; j <= n; j++) {
      cur[b[j]] = (cur[b[j]] + dp[i - 1][j - 1]) % mod;
      dp[i][j] = (dp[i - 1][j] + cur[a[i]]) % mod;
    }
  }
  cout << dp[n][m];
}
