#include <bits/stdc++.h>
using namespace std;
vector<long long> vt;
long long mod = 10e9 + 7;
int main() {
  long long n, m;
  cin >> n >> m;
  long long a[n], b[m], dp[m];
  for (long long i = 1; i <= m; i++) {
    dp[i] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (long long i = 1; i <= n; i++) {
    long long x = a[i];
    long long sum = 0;
    for (long long j = 1; j <= m; j++) {
      long long y = dp[j];
      if (b[j] == x) {
        dp[j] += (1 + sum) % mod;
        dp[j] = dp[j] % mod;
      }
      sum += y;
      sum = sum % mod;
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    ans += dp[i];
    ans = ans % mod;
  }
  cout << ans + 1 << endl;
}
