#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 1000006, MAXM = 1003, Mod = 1000000007 , MAXLog = 20;

int n, m;
int A[MAXM];
int B[MAXM];

int memo[MAXM][MAXM];

int solve(int i, int j) {
    if (i == n || j == m){
        return 0;
    }
    int &ret = memo[i][j];
    if (~ret)
        return ret;
    ret = 0;
    ret += (0LL + solve(i + 1, j) + solve(i, j + 1) - solve(i + 1, j + 1) + Mod) % Mod;
    ret %= Mod;
    if (A[i] == B[j]) {
        ret += solve(i + 1, j + 1) + 1;
    }
    ret %= Mod;
//    cout << i << ' ' << j << ' ' << ret << '\n';
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> B[i];
    }


    memset(memo, -1, sizeof memo);
    cout << (solve(0, 0) + 1) % Mod << '\n';

    return 0;
}