#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>
using namespace std;

int LevenshteinDist(const string& s, const string& t)
{
    int n = s.size();
    int m = t.size();
    vector<vector<int> > minCost(n+2, vector<int>(m+2, INT_MAX));
    minCost[0][0] = 0;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=m; ++j){
            minCost[i+1][j] = min(minCost[i+1][j], minCost[i][j] + 1);
            minCost[i][j+1] = min(minCost[i][j+1], minCost[i][j] + 1);
            if(i < n && j < m && s[i] == t[j])
                minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j]);
            else
                minCost[i+1][j+1] = min(minCost[i+1][j+1], minCost[i][j] + 1);
        }
    }
    return minCost[n][m];
}

class Edge{
public:
    int to, cap, cost, rev;
    Edge(){};
    Edge(int to0, int cap0, int cost0){to = to0; cap = cap0, cost = cost0;}
    Edge(int to0, int cap0, int cost0, int rev0){to = to0; cap = cap0; cost = cost0; rev = rev0;}
};

int minCostFlow(const vector<vector<Edge> >& edges0, int source, int sink, int flow)
{
    int n = edges0.size();
    vector<vector<Edge> > edges(n);
    for(int i=0; i<n; ++i){
        for(unsigned j=0; j<edges0[i].size(); ++j){
            const Edge& e = edges0[i][j];
            edges[i].push_back(Edge(e.to, e.cap, e.cost, edges[e.to].size()));
            edges[e.to].push_back(Edge(i, 0, -e.cost, edges[i].size()-1));
        }
    }

    vector<int> h(n, 0);
    vector<int> prevV(n);
    vector<int> prevE(n);

    int ret = 0;
    while(flow > 0){
        vector<int> dist(n, INT_MAX);
        dist[source] = 0;
        priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
        q.push(make_pair(0, source));

        while(!q.empty()){
            pair<int, int> p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)
                continue;
            for(unsigned i=0; i<edges[v].size(); ++i){
                Edge e = edges[v][i];
                if(e.cap > 0 && dist[v] + e.cost + h[v] - h[e.to] < dist[e.to]){
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevV[e.to] = v;
                    prevE[e.to] = i;
                    q.push(make_pair(dist[e.to], e.to));
                }
            }
        }
        if(dist[sink] == INT_MAX){
            return -1;
        }
        for(int i=0; i<n; ++i)
            h[i] += dist[i];

        int g = flow;
        for(int i=sink; i!=source; i=prevV[i])
            g = min(g, edges[prevV[i]][prevE[i]].cap);
        for(int i=sink; i!=source; i=prevV[i]){
            Edge& e = edges[prevV[i]][prevE[i]];
            e.cap -= g;
            edges[i][e.rev].cap += g;
        }
        flow -= g;
        ret += g * h[sink];
    }
    return ret;
}

int main()
{
    int n, m;
    cin >> n >> m;
    cin.ignore();

    string s;
    vector<string> t(m);
    for(int i=0; i<n; ++i){
        string tmp;
        getline(cin, tmp);
        s += tmp + ' ';
    }
    for(int i=0; i<m; ++i)
        cin >> t[i];

    istringstream iss(s);
    map<string, int> word;
    for(;;){
        string u;
        if(!(iss >> u))
            break;
        ++ word[u];
    }

    vector<vector<Edge> > edges(m+2+word.size());
    for(int i=0; i<m; ++i)
        edges[0].push_back(Edge(2+i, 1, 0));

    int k = m + 2;
    for(map<string, int>::iterator it=word.begin(); it!=word.end(); ++it){
        for(int i=0; i<m; ++i)
            edges[2+i].push_back(Edge(k, 1, LevenshteinDist(it->first, t[i]) * it->second));
        edges[k].push_back(Edge(1, 1, 0));
        ++ k;
    }

    cout << minCostFlow(edges, 0, 1, word.size()) << endl;

    return 0;
}

Measured memory_bytes: 11300