#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10, MOD = 1e9 + 7;
long long dd[N], temp[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1], b[n + 1];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long j = 0; j < m; j++) cin >> b[j];
  long long sum = 0;
  for (long long i = n - 1; i >= 0; i--) {
    sum = 0;
    for (long long j = m - 1; j >= 0; j--) {
      if (a[i] == b[j]) {
        dd[j] += sum + 1;
      }
      sum += temp[j];
    }
    for (long long j = 0; j < m; j++) {
      temp[j] = dd[j];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    ans += dd[i];
    ans = ans % MOD;
  }
  cout << (ans + 1) % MOD;
}
