#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v;
  long long cap, cost;
  Edge(int _u, int _v, long long _cap, long long _cost) {
    u = _u;
    v = _v;
    cap = _cap;
    cost = _cost;
  }
};
struct MinCostFlow {
  int n, s, t;
  long long flow, cost;
  vector<vector<int> > graph;
  vector<Edge> e;
  vector<long long> dist;
  vector<int> parent;
  MinCostFlow(int _n) {
    n = _n;
    graph.assign(n, vector<int>());
  }
  void addEdge(int u, int v, long long cap, long long cost,
               bool directed = true) {
    graph[u].push_back(e.size());
    e.push_back(Edge(u, v, cap, cost));
    graph[v].push_back(e.size());
    e.push_back(Edge(v, u, 0, -cost));
    if (!directed) addEdge(v, u, cap, cost, true);
  }
  pair<long long, long long> getMinCostFlow(int _s, int _t) {
    s = _s;
    t = _t;
    flow = 0, cost = 0;
    while (SPFA()) {
      flow += sendFlow(t, 1LL << 62);
    }
    return make_pair(flow, cost);
  }
  bool SPFA() {
    parent.assign(n, -1);
    dist.assign(n, 1LL << 62);
    dist[s] = 0;
    vector<int> queuetime(n, 0);
    queuetime[s] = 1;
    vector<bool> inqueue(n, 0);
    inqueue[s] = true;
    queue<int> q;
    q.push(s);
    bool negativecycle = false;
    while (!q.empty() && !negativecycle) {
      int u = q.front();
      q.pop();
      inqueue[u] = false;
      for (int i = 0; i < graph[u].size(); i++) {
        int eIdx = graph[u][i];
        int v = e[eIdx].v, w = e[eIdx].cost, cap = e[eIdx].cap;
        if (dist[u] + w < dist[v] && cap > 0) {
          dist[v] = dist[u] + w;
          parent[v] = eIdx;
          if (!inqueue[v]) {
            q.push(v);
            queuetime[v]++;
            inqueue[v] = true;
            if (queuetime[v] == n + 2) {
              negativecycle = true;
              break;
            }
          }
        }
      }
    }
    return dist[t] != (1LL << 62);
  }
  long long sendFlow(int v, long long curFlow) {
    if (parent[v] == -1) return curFlow;
    int eIdx = parent[v];
    int u = e[eIdx].u, w = e[eIdx].cost;
    long long f = sendFlow(u, min(curFlow, e[eIdx].cap));
    cost += f * w;
    e[eIdx].cap -= f;
    e[eIdx ^ 1].cap += f;
    return f;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int> > cnt(k, vector<int>(k, 0));
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    int c1 = s[i] >= 'a' ? s[i] - 'a' : s[i] - 'A' + 26;
    int c2 = t[i] >= 'a' ? t[i] - 'a' : t[i] - 'A' + 26;
    cnt[c1][c2]++;
  }
  MinCostFlow mcmf(k + k + 2);
  int src = 2 * k, snk = 2 * k + 1;
  for (int i = 0; i < k; i++) {
    mcmf.addEdge(src, i, 1, 0);
    mcmf.addEdge(i + k, snk, 1, 0);
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < k; j++) {
      mcmf.addEdge(i, j + k, 1, -cnt[i][j]);
    }
  }
  cout << -mcmf.getMinCostFlow(src, snk).second << endl;
  bool h = 0;
  vector<int> conv(k);
  for (auto ed : mcmf.e) {
    if (h && ed.v != src && ed.u != snk) {
      if (ed.cap) {
        conv[ed.v] = ed.u - k;
      }
    }
    h ^= 1;
  }
  for (int i = 0; i < k; i++) {
    if (conv[i] < 26) {
      cout << (char)('a' + conv[i]);
    } else {
      cout << (char)('A' + conv[i] - 26);
    }
  }
  return 0;
}
