#include<bits/stdc++.h>
using namespace std;

int main() {
  long long N,M;
  cin >> N >> M;
  vector<long long> S(N),T(M),ans(N,0);
  for (int i=0; i<N; i++) {
    cin >> S[i];
  }
  for (int i=0; i<M; i++) {
    cin >> T[i];
  }
  long long value = 1;
  
  for (int i=0; i<M; i++) {
    value = 1;
    for (int j=0; j<N; j++) {
      if (T[i] == S[j]) {
        ans[j] += value;
        ans[j] %= 1000000007;
        value = 0;
      }
      value += ans[j];
      value %= 1000000007;
    }
  }
  
  long long answer = 1;
  for (int i=0; i<N; i++) {
    answer += ans[i];
    answer %= 1000000007;
  }
  
  cout << answer << endl;
  
  return 0;
}