#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

template<int64_t mod>
struct ModInt {
    int64_t value;

    ModInt() : value(0) {}
    ModInt(int64_t x) : value(x >= 0 ? x % mod : (mod - ((-x) % mod) % mod)) {}

    ModInt &operator+=(const ModInt &input) {
        value += input.value;
        value %= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &input) {
        value += (mod - input.value);
        if (value >= mod) value -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &input) {
        value = ((value % mod) * (input.value % mod)) % mod;
        return *this;
    }

    ModInt &operator/=(const ModInt &input) {
        *this *= input.inverse();
        return *this;
    }

    ModInt inverse() const {
        int64_t base = value, p = mod;
        pair<int64_t, int64_t> save = {1, 0};
        while (p) {
            int64_t temp = base / p;
            swap(base -= temp * p, p);
            swap(save.first -= temp * save.second, save.second);
        }
        return ModInt(save.first);
    }

    ModInt operator-() const { return ModInt(-value); }

    ModInt operator-(const ModInt &input) const { return ModInt(*this) -= input; }

    ModInt operator+(const ModInt &input) const { return ModInt(*this) += input; }

    ModInt operator*(const ModInt &input) const { return ModInt(*this) *= input; }

    ModInt operator/(const ModInt &input) const { return ModInt(*this) /= input; }

    bool operator==(const ModInt &comparsion) const { return value == comparsion.value; }

    bool operator!=(const ModInt &comparsion) const { return value != comparsion.value; }

    friend istream &operator>>(istream &stream, ModInt &input) {
        int64_t temp;
        stream >> temp;
        input = ModInt<mod>(temp);
        return stream;
    }

    friend ostream &operator<<(ostream &stream, const ModInt &input) {
        return stream << input.value;
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), x(value);
        while (n > 0) {
            if (n and 1) ret *= x;
            x *= x;
            n >>= 1;
        }
        return ret;
    }

    static const int64_t get_mod() { return mod; }
};

using modint = ModInt<MOD>;

// Last updated 2020-4-22
template<typename T>
class BinaryIndexedTree {
private:
    vector<T> data;

public:
    explicit BinaryIndexedTree(size_t data_size) : data(data_size + 1, 0) {}

    void update(size_t index, T value) {
        for (size_t now_index = index + 1; now_index < data.size(); now_index += (now_index & -now_index)) {
            data[now_index] += value;
        }
    }

    T sum(size_t index) {
        T count_up = 0;
        for (size_t now_index = index + 1; now_index > 0; now_index -= (now_index & -now_index)) {
            count_up += data[now_index];
        }
        return count_up;
    }

    T sum_all() {
        return sum(data.size() - 1);
    }

    // [left, right)
    T query(int left_index, int right_index) {
        return sum(right_index - 1) - sum(left_index - 1);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(N + 1), T(M + 1);
    for (int i = 1; i <= N; i++) cin >> S[i];
    for (int i = 1; i <= M; i++) cin >> T[i];
    vector<vector<modint>>  dp(N + 1, vector<modint>(M + 1, 0));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (S[i] == T[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        }
        for (int j = 1; j <= M; j++) {
            dp[i][j] += dp[i][j - 1];
        }
        for (int j = 1; j <= M; j++) {
            dp[i][j] += dp[i - 1][j];
        }
    }

    cout << dp[N][M] + 1 << endl;
}


Measured memory_bytes: 31616