#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int str1[10000], str2[10000];
  for (int i = 0; i < n; i++) cin >> str1[i];
  for (int i = 0; i < n; i++) cin >> str2[i];
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str1[i] == str2[j]) {
        ans++;
        int c = 1;
        while (1) {
          if (i + c == n || j + c == m) break;
          if (str1[i + c] == str2[j + c])
            ans++;
          else
            break;
          c++;
        }
        ans = ans % 10000007;
      }
    }
  }
  cout << ans << endl;
}
