#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  long long to, cap, rev;
  Edge(long long _to, long long _cap, long long _rev) {
    to = _to;
    cap = _cap;
    rev = _rev;
  }
};
void add_edge(vector<vector<Edge>>& G, long long from, long long to,
              long long cap, bool revFlag, long long revCap) {
  G[from].push_back(Edge(to, cap, (long long)G[to].size()));
  if (revFlag)
    G[to].push_back(Edge(from, revCap, (long long)G[from].size() - 1));
}
long long max_flow_dfs(vector<vector<Edge>>& G, long long v, long long t,
                       long long f, vector<bool>& used) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); ++i) {
    Edge& e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      long long d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
long long max_flow(vector<vector<Edge>>& G, long long s, long long t) {
  long long flow = 0;
  for (;;) {
    vector<bool> used(G.size());
    for (int(i) = 0; (i) < (used.size()); (i)++) used[i] = false;
    long long f = max_flow_dfs(G, s, t, INF, used);
    if (f == 0) {
      return flow;
    }
    flow += f;
  }
}
void BellmanFord(vector<vector<Edge>>& G, long long s, vector<long long>& d,
                 vector<long long>& negative) {
  d.resize(G.size());
  negative.resize(G.size());
  for (int(i) = 0; (i) < (d.size()); (i)++) d[i] = INF;
  for (int(i) = 0; (i) < (d.size()); (i)++) negative[i] = false;
  d[s] = 0;
  for (int(k) = 0; (k) < (G.size() - 2); (k)++) {
    for (int(i) = 0; (i) < (G.size()); (i)++) {
      for (int(j) = 0; (j) < (G[i].size()); (j)++) {
        if (d[G[i][j].to] > d[i] + G[i][j].cap) {
          d[G[i][j].to] = d[i] + G[i][j].cap;
        }
      }
    }
  }
  for (int(k) = 0; (k) < (G.size() - 2); (k)++) {
    for (int(i) = 0; (i) < (G.size()); (i)++) {
      for (int(j) = 0; (j) < (G[i].size()); (j)++) {
        if (d[G[i][j].to] > d[i] + G[i][j].cap) {
          d[G[i][j].to] = d[i] + G[i][j].cap;
          negative[G[i][j].to] = true;
        }
        if (negative[i] == true) negative[G[i][j].to] = true;
      }
    }
  }
}
void Dijkstra(vector<vector<Edge>>& G, long long s, vector<long long>& d) {
  d.resize(G.size());
  for (int(i) = 0; (i) < (d.size()); (i)++) d[i] = INF;
  d[s] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    pair<long long, long long> a = q.top();
    q.pop();
    if (d[a.second] < a.first) continue;
    for (int(i) = 0; (i) < (G[a.second].size()); (i)++) {
      Edge e = G[a.second][i];
      if (d[e.to] > d[a.second] + e.cap) {
        d[e.to] = d[a.second] + e.cap;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
void WarshallFloyd(vector<vector<Edge>>& G, vector<vector<long long>>& d) {
  d.resize(G.size());
  for (int(i) = 0; (i) < (d.size()); (i)++) d[i].resize(G.size());
  for (int(i) = 0; (i) < (d.size()); (i)++) {
    for (int(j) = 0; (j) < (d[i].size()); (j)++) {
      d[i][j] = INF;
    }
  }
  for (int(i) = 0; (i) < (G.size()); (i)++) {
    for (int(j) = 0; (j) < (G[i].size()); (j)++) {
      d[i][G[i][j].to] = G[i][j].cap;
    }
  }
  for (int(i) = 0; (i) < (G.size()); (i)++) {
    for (int(j) = 0; (j) < (G.size()); (j)++) {
      for (int(k) = 0; (k) < (G.size()); (k)++) {
        chmin(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }
}
class UnionFind {
  vector<int> data;
  long long num;

 public:
  UnionFind(int size) : data(size, -1), num(size) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    num -= (x != y);
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
  int numSet() { return num; }
};
class SumSegTree {
 private:
  int _sum(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b)
      return dat[k];
    else {
      int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2);
      int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r);
      return s1 + s2;
    }
  }

 public:
  int n, height;
  vector<int> dat;
  SumSegTree(int _n) {
    n = 1;
    height = 1;
    while (n < _n) {
      n *= 2;
      height++;
    }
    dat = vector<int>(2 * n - 1);
  }
  void add(int i, int x) {
    i += n - 1;
    dat[i] += x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] += x;
    }
  }
  int sum(int a, int b) { return _sum(a, b, 0, 0, n); }
};
void divisor(long long n, vector<long long>& ret) {
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
}
vector<long long> lis_fast(const vector<long long>& a) {
  const long long n = a.size();
  vector<long long> A(n, INT_MAX);
  vector<long long> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
    A[id[i]] = a[i];
  }
  long long m = *max_element(id.begin(), id.end());
  vector<long long> b(m + 1);
  for (int i = n - 1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];
  return b;
}
long long ModPow(long long x, long long n) {
  long long res = 1LL;
  while (n > 0) {
    if (n & 1) res = res * x % 1000000007;
    x = x * x % 1000000007;
    n >>= 1;
  }
  return res;
}
class Combination {
 public:
  vector<long long> fact;
  vector<long long> inv;
  long long mod;
  long long mod_inv(long long x) {
    long long n = mod - 2LL;
    long long res = 1LL;
    while (n > 0) {
      if (n & 1) res = res * x % mod;
      x = x * x % mod;
      n >>= 1;
    }
    return res;
  }
  long long nCr(long long n, long long r) {
    return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
  }
  long long nPr(long long n, long long r) {
    return (fact[n] * inv[n - r]) % mod;
  }
  Combination(long long n, long long _mod) {
    mod = _mod;
    fact.resize(n + 1);
    fact[0] = 1;
    for (int(i) = 0; (i) < (n); (i)++) {
      fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
    }
    inv.resize(n + 1);
    for (int(i) = 0; (i) < (n + 1); (i)++) {
      inv[i] = mod_inv(fact[i]);
    }
  }
};
bool compare_by_b(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}
bool compare_by_a(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first) {
    return a.first > b.first;
  } else {
    return a.second > b.second;
  }
}
long long gcd(long long m, long long n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}
long long lcm(long long m, long long n) { return m / gcd(m, n) * n; }
vector<vector<long long>> mIdentity(long long n) {
  vector<vector<long long>> A(n, vector<long long>(n));
  for (int i = 0; i < n; ++i) A[i][i] = 1;
  return A;
}
vector<vector<long long>> mMul(const vector<vector<long long>>& A,
                               const vector<vector<long long>>& B) {
  vector<vector<long long>> C(A.size(), vector<long long>(B[0].size()));
  for (int i = 0; i < C.size(); ++i)
    for (int j = 0; j < C[i].size(); ++j)
      for (int k = 0; k < A[i].size(); ++k)
        (C[i][j] += (A[i][k] % 1000000007) * (B[k][j] % 1000000007)) %=
            1000000007;
  return C;
}
vector<vector<long long>> mPow(const vector<vector<long long>>& A,
                               long long e) {
  return e == 0       ? mIdentity(A.size())
         : e % 2 == 0 ? mPow(mMul(A, A), e / 2)
                      : mMul(A, mPow(A, e - 1));
}
long long dp[2001][2001];
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (int(i) = 0; (i) < (n); (i)++) cin >> s[i];
  for (int(i) = 0; (i) < (m); (i)++) cin >> t[i];
  dp[0][0] = 1;
  for (int(i) = 0; (i) < (n + 1); (i)++) {
    dp[i][0] = 1;
  }
  for (int(i) = 0; (i) < (m + 1); (i)++) {
    dp[0][i] = 1;
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (m); (j)++) {
      if (s[i] == t[j]) {
        (dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1]) %= 1000000007;
      } else {
        (dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) %=
            1000000007;
      }
    }
  }
  cout << dp[n][m];
  return 0;
}
