#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class AhoCorasick
{
    int n;
    vector<vector<int> > next;
    vector<bitset<64> > match;
    vector<int> failure;
public:
    AhoCorasick(const vector<string>& pattern){
        next.assign(1, vector<int>(128, -1));
        match.assign(1, 0);
        for(unsigned i=0; i<pattern.size(); ++i){
            int curr = 0;
            for(unsigned j=0; j<pattern[i].size(); ++j){
                if(next[curr][pattern[i][j]] == -1){
                    next[curr][pattern[i][j]] = next.size();
                    next.push_back(vector<int>(128, -1));
                    match.push_back(0);
                }
                curr = next[curr][pattern[i][j]];
            }
            match[curr][i] = true;
        }

        n = next.size();
        failure.resize(n, 0);
        vector<int> node1(1, 0);
        while(!node1.empty()){
            vector<int> node2;
            for(unsigned i=0; i<node1.size(); ++i){
                for(int j=0; j<128; ++j){
                    int s = node1[i];
                    if(next[s][j] == -1)
                        continue;
                    node2.push_back(next[s][j]);
                    int t = s;
                    while(t != 0){
                        if(next[failure[t]][j] != -1){
                            failure[next[s][j]] = next[failure[t]][j];
                            match[next[s][j]] |= match[next[failure[t]][j]];
                            break;
                        }
                        t = failure[t];
                    }
                }
            }
            node1.swap(node2);
        }
    }
    int size(){
        return n;
    }
    int transition(int curr, char c){
        if(next[curr][c] != -1)
            return next[curr][c];
        if(curr == 0)
            return 0;
        return transition(failure[curr], c);
    }
    bitset<64> checkMatch(int curr){
        return match[curr];
    }
};

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<string> element(n);
        for(int i=0; i<n; ++i)
            cin >> element[i];
        AhoCorasick ac(element);

        string s;
        while(--m >= 0){
            string t;
            cin >> t;
            s += t;
        }
        int len = s.size();

        int ret = 0;
        vector<vector<bool> > dp(1<<n, vector<bool>(len+1, false));
        dp[0] = vector<bool>(len+1, true);

        int curr = 0;
        for(int i=0; i<len; ++i){
            curr = ac.transition(curr, s[i]);
            bitset<64> match = ac.checkMatch(curr);
            for(int j=0; j<(1<<n); ++j){
                bitset<64> bs(j);
                for(int k=0; k<n; ++k){
                    if(match[k] && !bs[k]){
                        bs[k] = true;
                        if(dp[j][i+1-element[k].size()])
                            dp[bs.to_ulong()][i+1] = true;
                        bs[k] = false;
                    }
                }
            }
            if(dp[(1<<n)-1][i+1])
                ++ ret;
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 3924