#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<long long> s, t;
long long cnt = 1;
void dfs(bool sflag, long long sfirst, long long send, long long tfirst,
         long long tend) {
  long long sf = sfirst;
  long long se = send;
  long long tf = tfirst;
  long long te = tend;
  if (sflag) {
    if (tf - 1 >= 0) {
      while (sf > 0) {
        sf--;
        for (long long i = tf - 1; i >= 0; i--) {
          if (s[sf] == t[i]) {
            cnt++;
            cnt = (cnt + mod) % mod;
            dfs(sflag, sf, se, i, te);
          }
        }
      }
      sf = sfirst;
    }
  } else {
    if (sf - 1 >= 0) {
      while (tf > 0) {
        tf--;
        for (long long i = sf - 1; i >= 0; i--) {
          if (s[i] == t[tf]) {
            cnt++;
            cnt = (cnt + mod) % mod;
            dfs(sflag, i, se, tf, te);
          }
        }
      }
      tf = tfirst;
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  s.resize(n);
  t.resize(m);
  for (long long(i) = 0; (i) < (n); (i)++) cin >> s[i];
  for (long long(i) = 0; (i) < (m); (i)++) cin >> t[i];
  if (n >= m) {
    for (long long(i) = 0; (i) < (m); (i)++) {
      for (long long(j) = 0; (j) < (n); (j)++) {
        if (s[j] == t[i]) {
          cnt++;
          dfs(false, j, j, i, i);
        }
      }
    }
  } else {
    for (long long(i) = 0; (i) < (n); (i)++) {
      for (long long(j) = 0; (j) < (m); (j)++) {
        if (s[i] == t[j]) {
          cnt++;
          dfs(true, i, i, j, j);
        }
      }
    }
  }
  cout << cnt << endl;
}
