#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<vector<int>> vt;
int dp[2010][2010][2][2];
int a[2010];
int b[2010];
int n, m;
int func(int here, int here1, int ch, int ch1) {
  if (here == n || here1 == m) {
    if (ch && !ch1)
      return 1;
    else
      return 0;
  }
  int &ret = dp[here][here1][ch][ch1];
  if (ret != -1) return ret;
  ret = 0;
  if (!ch1) ret += func(here + 1, here1, ch, 0);
  ret %= mod;
  int t = lower_bound(vt[a[here]].begin(), vt[a[here]].end(), here1) -
          vt[a[here]].begin();
  if (t != vt[a[here]].size()) {
    ret += (func(here + 1, vt[a[here]][t] + 1, 1, 0));
    ret %= mod;
    if (!ch1) ret += func(here, vt[a[here]][t] + 1, ch, 1);
    ret %= mod;
  }
  return ret;
}
int main() {
  vt.resize(100001);
  memset(dp, -1, sizeof(dp));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    vt[b[i]].push_back(i);
  }
  printf("%d", func(0, 0, 0, 0) + 1);
}
