#include <bits/stdc++.h>
using namespace std;
template <typename T>
class MyVector : private std::vector<T, std::allocator<T>> {
 public:
  using basetype = std::vector<T, std::allocator<T>>;
  using basetype::vector;
  using basetype::operator=;
  using basetype::begin;
  using basetype::capacity;
  using basetype::cbegin;
  using basetype::cend;
  using basetype::crbegin;
  using basetype::crend;
  using basetype::empty;
  using basetype::end;
  using basetype::max_size;
  using basetype::rbegin;
  using basetype::rend;
  using basetype::reserve;
  using basetype::resize;
  using basetype::shrink_to_fit;
  using basetype::size;
  typename MyVector<T>::reference operator[](typename basetype::size_type n) {
    basetype::at(n);
  }
  typename MyVector<T>::const_reference operator[](
      typename basetype::size_type n) const {
    basetype::at(n);
  };
  using basetype::assign;
  using basetype::at;
  using basetype::back;
  using basetype::clear;
  using basetype::data;
  using basetype::emplace;
  using basetype::emplace_back;
  using basetype::erase;
  using basetype::front;
  using basetype::insert;
  using basetype::pop_back;
  using basetype::push_back;
  using basetype::swap;
};
const double PI = acos(-1.0);
const double EPS = 1e-10;
int powint(int a, int x) {
  int res = 1;
  for (int i = (0); i < (x); ++i) {
    res = res * a;
  }
  return res;
}
const long long MOD = 1e9 + 7;
signed main() {
  const long long N = []() {
    long long t;
    cin >> t;
    return t;
  }();
  const long long M = []() {
    long long t;
    cin >> t;
    return t;
  }();
  std::vector<long long> S(N);
  std::vector<long long> T(M);
  for (long long i = (0); i < (N); ++i) {
    cin >> S[i];
  }
  for (long long j = (0); j < (M); ++j) {
    cin >> T[j];
  }
  std::vector<std::vector<long long>> DP(N, std::vector<long long>(M));
  for (long long i = (0); i < (N); ++i) {
    long long p = S[i];
    for (long long j = (0); j < (M); ++j) {
      long long q = T[j];
      if (p == q) {
        if (i > 0 && j > 0)
          DP[i][j] = 1 + DP[i - 1][j] + DP[i][j - 1];
        else if (i > 0)
          DP[i][j] = 1 + DP[i - 1][j];
        else if (j > 0)
          DP[i][j] = 1 + DP[i][j - 1];
        else
          DP[i][j] = 1;
      } else {
        if (i > 0 && j > 0)
          DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
        else if (i > 0)
          DP[i][j] = DP[i - 1][j];
        else if (j > 0)
          DP[i][j] = DP[i][j - 1];
      }
      DP[i][j] = DP[i][j] % MOD;
    }
  }
  long long ans = (DP[N - 1][M - 1] + 1) % MOD;
  cout << ans << endl;
  return 0;
}
