#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf_s("%d", &f); in(r...); }
template<typename... R> void input(double& f, R&... r) { scanf_s("%lf", &f); in(r...); }
template<typename... R> void input(long long& f, R&... r) { scanf_s("%lld", &f); in(r...); }
template<typename... R> void input(char& f, R&... r) { scanf_s("%c", &f); in(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; in(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())in(f[i]); in(r...); }
#pragma endregion

// LCS 最長共通部分列
template<typename T>
ll LCS(const vector<T> &A, const vector<T> &B) {
    int n = A.size(), m = B.size();
    vector<vector<ll>> lcs(n + 1, vector <ll>(m + 1));
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (i == 0 || j == 0) {
                lcs[i][j] = 1;
            }
            else if (A[i - 1] == B[j - 1]) {
                lcs[i][j] = (lcs[i][j - 1] + lcs[i - 1][j]) % MOD;
            }
            else {
                lcs[i][j] = (lcs[i][j - 1] + lcs[i - 1][j] + MOD - lcs[i - 1][j - 1]) % MOD;
            }
        }
    }
    return lcs[n][m];
}

int main() {
    int N, M; cin >> N >> M;
    vector<ll> S(N);
    vector<ll> T(M);
    input(S, T);
    cout << LCS(S, T) << endl;
    getchar(); getchar();
}