#include <bits/stdc++.h>
using namespace std;
namespace {
template <typename T, typename K>
struct Pair {
  T fst;
  K snd;
  bool operator<(const Pair& p) const {
    if (fst != p.fst) return fst < p.fst;
    return snd < p.snd;
  }
};
template <typename T, typename K>
std::istream& operator>>(std::istream& in, Pair<T, K>& p) {
  return in >> p.fst >> p.snd;
}
template <typename T, typename K, typename H>
struct Trir {
  T fst;
  K snd;
  H trd;
  bool operator<(const Trir& t) const {
    if (fst != t.fst) return fst < t.fst;
    if (snd != t.snd) return snd < t.snd;
    return trd < t.trd;
  }
};
template <typename T, typename K, typename H>
std::istream& operator>>(std::istream& in, Trir<T, K, H>& p) {
  return in >> p.fst >> p.snd >> p.trd;
}
const int Ten5 = 100000;
const int Ten6 = 1000000;
const double EPS = 0.00000000023283064365386962890625;
}  // namespace
namespace {
class Mod {
 public:
  typedef long long T;
  static T N;
  Mod operator+(T v) const { return Mod(x + v % N); }
  Mod operator+(Mod m) const { return Mod(x + m.x); }
  Mod operator+=(T v) { return *this = Mod(x + v % N); }
  Mod operator+=(Mod m) { return *this = Mod(x + m.x); }
  Mod operator-(T v) const { return Mod(x - v + N); }
  Mod operator-(Mod m) const { return Mod(x - m.x + N); }
  Mod operator-=(T v) { return *this = Mod(x - v + N); }
  Mod operator-=(Mod m) { return *this = Mod(x - m.x + N); }
  Mod operator*(T v) const { return Mod(x * v); }
  Mod operator*(Mod m) const { return Mod(x * m.x); }
  Mod operator*=(T v) { return *this = Mod(x * v); }
  Mod operator*=(Mod m) { return *this = Mod(x * m.x); }
  Mod operator/(T v) const {
    const T n = N - 2;
    T r = x;
    for (T b = 1; b < n; b <<= 1) {
      if (n & b) r = r * v % N;
      v = v * v % N;
    }
    return r;
  }
  Mod operator/(Mod m) const {
    const T n = N - 2;
    T v = m.x, r = x;
    for (T b = 1; b < n; b <<= 1) {
      if (n & b) r = r * v % N;
      v = v * v % N;
    }
    return r;
  }
  Mod operator/=(T v) { return *this = *this / v; }
  Mod operator/=(Mod m) { return *this = *this / m; }
  operator T() const { return x; }
  Mod() {}
  Mod(T v) : x(v % N) {}

 private:
  T x;
};
Mod::T Mod::N = 1000 * 1000 * 1000 + 7;
template <typename T>
class Max {
 public:
  int cnt() const { return c; }
  bool operator=(T v) {
    if (!c) {
      c = 1;
      x = v;
      return true;
    }
    if (x < v) {
      c++;
      x = v;
      return true;
    }
    return false;
  }
  operator T() const { return x; }
  Max() : x(0), c(0) {}
  Max(T v) : x(v), c(1) {}
  Max(const T* f, const T* l) : x(*f++), c(1) {
    while (f < l) {
      *this = *f++;
    }
  }
  Max(const T* a, int n) : x(0), c(0) {
    for (int i = 0, forEndi = ((int)(n)); i < forEndi; ++i) *this = *a++;
  }

 private:
  T x;
  int c;
};
template <typename T>
class Min {
 public:
  int cnt() const { return c; }
  bool operator=(T v) {
    if (!c) {
      c = 1;
      x = v;
      return true;
    }
    if (v < x) {
      c++;
      x = v;
      return true;
    }
    return false;
  }
  operator T() const { return x; }
  Min() : x(0), c(0) {}
  Min(T v) : x(v), c(1) {}
  Min(const T* f, const T* l) : x(*f++), c(1) {
    while (f < l) {
      *this = *f++;
    }
  }
  Min(const T* a, int n) : x(0), c(0) {
    for (int i = 0, forEndi = ((int)(n)); i < forEndi; ++i) *this = *a++;
  }

 private:
  T x;
  int c;
};
istream& operator>>(istream& in, Mod& m) {
  Mod::T t;
  in >> t;
  m = Mod(t);
  return in;
}
ostream& operator<<(ostream& ot, Mod m) { return ot << ((Mod::T)(m)); }
template <typename T>
istream& operator>>(istream& in, Max<T>& m) {
  T t;
  in >> t;
  m = Max<T>(t);
  return in;
}
template <typename T>
ostream& operator<<(ostream& ot, Max<T> m) {
  return ot << ((T)(m));
}
template <typename T>
istream& operator>>(istream& in, Min<T>& m) {
  T t;
  in >> t;
  m = Min<T>(t);
  return in;
}
template <typename T>
ostream& operator<<(ostream& ot, Min<T> m) {
  return ot << ((T)(m));
}
}  // namespace
namespace {
class Pint {
 public:
  int x, y;
  static const Pint dir[8];
  static void setup(int width, int height, int offset = -1, bool swap = false) {
    Width = width;
    Height = height;
    Offset = offset;
    Swap = swap;
  }
  inline bool isInFld() const {
    return 0 <= x && x < Width && 0 <= y && y < Height;
  }
  inline double len() const { return sqrt(sq()); }
  inline double len(const Pint& p) const { return sqrt(sq(p)); }
  inline int sq() const { return x * x + y * y; }
  inline int sq(const Pint& p) const {
    return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);
  }
  inline int manhattan() const { return abs(x) + abs(y); }
  inline int manhattan(const Pint& p) const {
    return abs(x - p.x) + abs(y - p.y);
  }
  inline int dot(const Pint& p) const { return x * p.x + y * p.y; }
  inline int crs(const Pint& p) const { return x * p.y - y * p.x; }
  inline Pint operator+() { return Pint(x, y); }
  inline Pint operator-() { return Pint(-x, -y); }
  inline Pint operator+(const Pint& p) const { return Pint(x + p.x, y + p.y); }
  inline const Pint& operator+=(const Pint& p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  inline Pint operator-(const Pint& p) const { return Pint(x - p.x, y - p.y); }
  inline const Pint& operator-=(const Pint& p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }
  inline Pint operator*(const Pint& p) const { return Pint(x * p.x, y * p.y); }
  inline const Pint& operator*=(const Pint& p) {
    x *= p.x;
    y *= p.y;
    return *this;
  }
  inline Pint operator/(const Pint& p) const { return Pint(x / p.x, y / p.y); }
  inline const Pint& operator/=(const Pint& p) {
    x /= p.x;
    y /= p.y;
    return *this;
  }
  inline Pint operator*(const int k) const { return Pint(x * k, y * k); }
  inline const Pint& operator*=(const int k) {
    x *= k;
    y *= k;
    return *this;
  }
  inline Pint operator/(const int k) const { return Pint(x / k, y / k); }
  inline const Pint& operator/=(const int k) {
    x /= k;
    y /= k;
    return *this;
  }
  inline bool operator<(const Pint& p) const {
    return x == p.x ? y < p.y : x < p.x;
  }
  inline bool operator>(const Pint& p) const {
    return x == p.x ? y > p.y : x > p.x;
  }
  inline bool operator==(const Pint& p) const { return x == p.x && y == p.y; }
  inline bool operator!=(const Pint& p) const { return x != p.x || y != p.y; }
  Pint() {}
  Pint(const int x, const int y) : x(x), y(y) {}

 private:
  friend istream& operator>>(istream& in, Pint& p);
  friend ostream& operator<<(ostream& out, const Pint& p);
  static int Width, Height, Offset;
  static bool Swap;
};
istream& operator>>(istream& in, Pint& p) {
  int x, y;
  in >> x >> y;
  x += Pint::Offset;
  y += Pint::Offset;
  if (Pint::Swap)
    p = Pint(y, x);
  else
    p = Pint(x, y);
  return in;
}
ostream& operator<<(ostream& out, const Pint& p) {
  return out << "( " << p.x << ", " << p.y << " )";
}
int Pint::Width, Pint::Height, Pint::Offset;
bool Pint::Swap;
const Pint Pint::dir[8] = {Pint(0, 1), Pint(1, 0),  Pint(0, -1), Pint(-1, 0),
                           Pint(1, 1), Pint(1, -1), Pint(-1, 1), Pint(-1, -1)};
class Pdouble {
 public:
  double x, y;
  inline double len() const { return sqrt(sq()); }
  inline double len(const Pdouble& p) const { return sqrt(sq(p)); }
  inline double sq() const { return x * x + y * y; }
  inline double sq(const Pdouble& p) const {
    return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);
  }
  inline Pdouble norm(const double l = 1.0) { return *this * l / len(); }
  inline double dot(const Pdouble& p) const { return x * p.x + y * p.y; }
  inline double crs(const Pdouble& p) const { return x * p.y - y * p.x; }
  inline Pdouble proj(const Pdouble& v) const {
    const double s = v.sq();
    if (s < EPS * EPS) return Pdouble(0, 0);
    return v * dot(v) / s;
  }
  inline Pdouble rot(const double rad) const {
    const double c = cos(rad), s = sin(rad);
    return Pdouble(c * x - s * y, s * x + c * y);
  }
  inline Pdouble operator+() { return Pdouble(x, y); }
  inline Pdouble operator-() { return Pdouble(-x, -y); }
  inline Pdouble operator+(const Pdouble& p) const {
    return Pdouble(x + p.x, y + p.y);
  }
  inline const Pdouble& operator+=(const Pdouble& p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  inline Pdouble operator-(const Pdouble& p) const {
    return Pdouble(x - p.x, y - p.y);
  }
  inline const Pdouble& operator-=(const Pdouble& p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }
  inline Pdouble operator*(const Pdouble& p) const {
    return Pdouble(x * p.x, y * p.y);
  }
  inline const Pdouble& operator*=(const Pdouble& p) {
    x *= p.x;
    y *= p.y;
    return *this;
  }
  inline Pdouble operator/(const Pdouble& p) const {
    return Pdouble(x / p.x, y / p.y);
  }
  inline const Pdouble& operator/=(const Pdouble& p) {
    x /= p.x;
    y /= p.y;
    return *this;
  }
  inline Pdouble operator*(const double k) const {
    return Pdouble(x * k, y * k);
  }
  inline const Pdouble& operator*=(const double k) {
    x *= k;
    y *= k;
    return *this;
  }
  inline Pdouble operator/(const double k) const {
    return Pdouble(x / k, y / k);
  }
  inline const Pdouble& operator/=(const double k) {
    x /= k;
    y /= k;
    return *this;
  }
  inline bool operator<(const Pdouble& p) const {
    return x == p.x ? y < p.y : x < p.x;
  }
  inline bool operator>(const Pdouble& p) const {
    return x == p.x ? y > p.y : x > p.x;
  }
  inline bool operator==(const Pdouble& p) const {
    return x == p.x && y == p.y;
  }
  inline bool operator!=(const Pdouble& p) const {
    return x != p.x || y != p.y;
  }
  Pdouble() {}
  Pdouble(const double x, const double y) : x(x), y(y) {}
  Pdouble(const Pint& p) : x(p.x), y(p.y) {}
};
istream& operator>>(istream& in, Pdouble& p) { return in >> p.x >> p.y; }
ostream& operator<<(ostream& out, const Pdouble& p) {
  return out << "( " << p.x << ", " << p.y << " )";
}
bool CollisionLine(const Pdouble lP, const Pdouble lQ, const Pdouble nP,
                   const Pdouble nQ) {
  auto sign = [](double d) { return d < 0 ? -1 : d > 0 ? 1 : 0; };
  Pdouble v = lQ - lP;
  if (sign(v.crs(nP - lP)) == sign(v.crs(nQ - lQ))) return false;
  v = nQ - nP;
  return sign(v.crs(lP - nP)) * sign(v.crs(lQ - nP)) <= 0;
}
}  // namespace
namespace {
void Zaatu(int* x, int N) {
  map<int, int> map;
  for (int i = 0, forEndi = ((int)(N)); i < forEndi; ++i)
    map.insert(std::pair<int, int>(x[i], 0));
  int idx = 0;
  for (auto itr = map.begin(), forEnditr = map.end(); itr != forEnditr; ++itr)
    itr->second = idx++;
  for (int i = 0, forEndi = ((int)(N)); i < forEndi; ++i) x[i] = map[x[i]];
}
void DoubleOut(double d, char c = '\n') { printf("%.12f%c", d, c); }
}  // namespace
int DP[2000][2000];
int SumDP[2000][2000];
int Count(int N, int M, int* S, int* T) {
  int Mon = (int)Mod::N;
  for (int k = 0, forEndk = ((int)(N)); k < forEndk; ++k) {
    for (int i = 0, forEndi = ((int)(N)); i < forEndi; ++i) {
      if (S[i] == T[k]) {
        int d = 1;
        if (k > 0 && i > 0) d = (d + SumDP[k - 1][i - 1]) % Mon;
        SumDP[k][i] = DP[k][i] = d;
      }
    }
    if (k > 0) {
      SumDP[k][0] = (SumDP[k - 1][0] + SumDP[k][0]) % Mon;
      for (int i = ((int)(1)), forEndi = ((int)(N)); i < forEndi; ++i) {
        SumDP[k][i] = (SumDP[k - 1][i] + SumDP[k][i]) % Mon;
        SumDP[k][i] = (SumDP[k][i - 1] + SumDP[k][i]) % Mon;
        SumDP[k][i] = (Mon - SumDP[k - 1][i - 1] + SumDP[k][i]) % Mon;
      }
    } else {
      SumDP[0][0] = DP[0][0];
      for (int i = ((int)(1)), forEndi = ((int)(N)); i < forEndi; ++i)
        SumDP[0][i] = (SumDP[0][i - 1] + DP[0][i]) % Mon;
    }
  }
  int ans = 1;
  for (int k = 0, forEndk = ((int)(N)); k < forEndk; ++k)
    for (int i = 0, forEndi = ((int)(N)); i < forEndi; ++i) {
      ans = (ans + DP[k][i]) % Mon;
    }
  return ans;
}
int main() {
  int N, M;
  cin >> N >> M;
  int S[2000], T[2000];
  for (int i = 0, forEndi = ((int)(N)); i < forEndi; ++i) cin >> S[i];
  for (int i = 0, forEndi = ((int)(M)); i < forEndi; ++i) cin >> T[i];
  int ans = N < M ? Count(M, N, T, S) : Count(N, M, S, T);
  cout << ans << endl;
  return 0;
}
