#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)


const int MOD = 1000000007;

int N, M;
vector<long long> S, T;

mint dp[2100][2100];
mint sdp[2100][2100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N >> M) {
        S.resize(N+1); T.resize(M+1);
        for (int i = 0; i < N; ++i) cin >> S[i];
        for (int i = 0; i < M; ++i) cin >> T[i];

        memset(dp, 0, sizeof(dp));
        memset(sdp, 0, sizeof(sdp));
        dp[0][0] = 1;
        sdp[0][0] = 1;
        for (int i = 0; i < 2100; ++i) sdp[0][i] = 1, sdp[i][0] = 1;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < M; ++j) {
                if (i < N && j < M && S[i] == T[j]) {
                    dp[i+1][j+1] = sdp[i][j];
                }
                sdp[i+1][j+1] = sdp[i][j+1] + sdp[i+1][j] - sdp[i][j] + dp[i+1][j+1];
            }
        }
        cout << sdp[N][M] << endl;
    }
}












