#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
ll fastPowMod(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}
template <typename T = int>
struct BinaryIndexedTree {
  int n;
  vector<T> bit;
  BinaryIndexedTree(int n_, T init = 0) : n(n_), bit(n_ + 1, init) {}
  BinaryIndexedTree(vector<T> init) : n(init.size() + 1), bit(init.size() + 1) {
    for (int i = 1; i < init.size() + 1; ++i) {
      bit[i] = init[i - 1];
    }
  }
  T sum(int i) {
    T s = bit[0];
    for (int x = i; x > 0; x -= (x & -x)) s += bit[x];
    return s;
  }
  void add(int i, T a) {
    if (i == 0) return;
    for (int x = i; x <= n; x += (x & -x)) bit[x] += a;
  }
  int lower_bound(int w) {
    if (w <= 0) return 0;
    int x = 0, r = 1;
    while (r < n) r <<= 1;
    for (int k = r; k > 0; k >>= 1) {
      if (x + k <= n && bit[x + k] < w) {
        w -= bit[x + k];
        x += k;
      }
    }
    return x + 1;
  }
  T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
};
int main() {
  int n, m;
  cin >> n >> m;
  vi s(n);
  vi t(m);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> t[i];
  }
  ll ret = 1;
  vl init(m + 3, 0);
  init[0] = 1;
  BinaryIndexedTree<ll> tr(init);
  vl dp(m + 1, 0);
  for (int i = 0; i < n; ++i) {
    vl js;
    vl subs;
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        ll temp = tr.query(0 + 1, j + 2);
        js.push_back(j);
        ret = (ret + temp) % MOD;
        temp = temp * 2 % MOD;
        subs.push_back(temp);
      }
    }
    ll tt;
    for (int j = 0; j < js.size(); ++j) {
      tt = tr.query(1, js[j] + 2);
      tr.add(js[j] + 2, subs[j]);
    }
  }
  cout << ret << "\n";
  return 0;
}
