#include <bits/stdc++.h>
using namespace std;

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

template <unsigned P>
struct ModInt {
    using M = ModInt;
    unsigned v;
    ModInt() : v(0) {}
    ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
    constexpr ModInt(unsigned v, int) : v(v) {}
    static constexpr unsigned p() { return P; }
    M operator+() const { return *this; }
    M operator-() const { return {v ? P - v : 0, 0}; }
    explicit operator bool() const noexcept { return v; }
    bool operator!() const noexcept { return !(bool)*this; }
    M operator*(M r) const { return M(*this) *= r; }
    M operator/(M r) const { return M(*this) /= r; }
    M operator+(M r) const { return M(*this) += r; }
    M operator-(M r) const { return M(*this) -= r; }
    bool operator==(M r) const { return v == r.v; }
    bool operator!=(M r) const { return !(*this == r); }
    M& operator*=(M r) {
        v = (uint64_t)v * r.v % P;
        return *this;
    }
    M& operator/=(M r) { return *this *= r.inv(); }
    M& operator+=(M r) {
        if ((v += r.v) >= P) v -= P;
        return *this;
    }
    M& operator-=(M r) {
        if ((v += P - r.v) >= P) v -= P;
        return *this;
    }
    M inv() const {
        int a = v, b = P, x = 1, u = 0;
        while (b) {
            int q = a / b;
            swap(a -= q * b, b);
            swap(x -= q * u, u);
        }
        assert(a == 1);
        return x;
    }
    M pow(auto n) const {
        if (n < 0) return pow(-n).inv();
        M res = 1;
        for (M a = *this; n; a *= a, n >>= 1)
            if (n & 1) res *= a;
        return res;
    }
    friend M operator*(auto l, M r) { return M(l) *= r; }
    friend M operator/(auto l, M r) { return M(l) /= r; }
    friend M operator+(auto l, M r) { return M(l) += r; }
    friend M operator-(auto l, M r) { return M(l) -= r; }
    friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
    friend istream& operator>>(istream& is, M& r) {
        int x;
        is >> x;
        r = x;
        return is;
    }
    friend bool operator==(auto l, M r) { return M(l) == r; }
    friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned)1e9 + 7>;

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vec s(n + 1), t(m + 1);
    For(i, 1, n) cin >> s[i];
    For(i, 1, m) cin >> t[i];

    vector<vector<Mint>> dp(n + 1, vector<Mint>(m + 1));

    rep (i, n + 1)
        dp[i][0] = 1;
    rep (i, m + 1)
        dp[0][i] = 1;

    For(i, 1, n) {
        For(j, 1, m) {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            if (s[i] != t[j]) dp[i][j] -= dp[i - 1][j - 1];
        }
    }
    print(dp[n][m]);

    return 0;
}


Measured memory_bytes: 16000