#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int cnt[113][113];
struct edge {
  int v;
  int cap;
  int cost;
  int flow;
  int num;
  size_t rev;
};
void insert(vector<vector<edge>> &gr, int u, int v, int cap, int cost,
            int num = 0) {
  gr[u].push_back({v, cap, cost, 0, num, gr[v].size()});
  gr[v].push_back({u, 0, -cost, 0, -1, gr[u].size() - 1});
}
int ctoi(char c) {
  if ('a' <= c && c <= 'z') {
    return c - 'a';
  } else {
    return c - 'A' + 26;
  }
}
char itoc(int i) {
  if (i < 26) {
    return static_cast<char>(i + 'a');
  } else {
    return static_cast<char>(i - 26 + 'A');
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<edge>> gr(113);
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < s1.size(); ++i) {
    ++cnt[ctoi(s1[i])][ctoi(s2[i])];
  }
  int s = 0, t = 105;
  for (int i = 1; i <= k; ++i) {
    insert(gr, s, i, 1, 0);
  }
  for (int i = 53; i < 53 + k; ++i) {
    insert(gr, i, t, 1, 0);
  }
  for (int i = 1; i <= k; ++i) {
    for (int j = 53; j < 53 + k; ++j) {
      insert(gr, i, j, 1, -cnt[i - 1][j - 53]);
    }
  }
  n = 106;
  int flow = 0;
  int cost = 0;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    p[i] = INF;
  }
  p[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int v = 0; v < n; ++v) {
      if (p[v] != INF) {
        for (auto &u : gr[v]) {
          if (u.cap > 0 && p[u.v] > p[v] + u.cost) {
            p[u.v] = p[v] + u.cost;
          }
        }
      }
    }
  }
  int a = s;
  int h = t;
  vector<int> ans(n);
  while (true) {
    vector<int> d(n, INF);
    vector<char> b(n, 0);
    vector<int> prev(n);
    d[a] = 0;
    priority_queue<pair<int, int>> q;
    q.push({0, a});
    while (!q.empty()) {
      int v = q.top().second;
      int w = -q.top().first;
      q.pop();
      if (b[v]) continue;
      b[v] = 1;
      d[v] = w;
      for (auto &u : gr[v]) {
        if (u.cap > u.flow) {
          int to = u.v;
          int tow = u.cost;
          if (!b[to] && d[to] > w + tow + p[v] - p[to]) {
            d[to] = w + tow + p[v] - p[to];
            prev[to] = u.rev;
            q.push({-d[to], to});
          }
        }
      }
    }
    if (!b[h]) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      if (b[i]) {
        p[i] += d[i];
      }
    }
    int add = k - flow;
    for (int v = h; v != a;) {
      int l = gr[v][prev[v]].v;
      int r = gr[v][prev[v]].rev;
      add = min(add, gr[l][r].cap - gr[l][r].flow);
      v = l;
    }
    for (int v = h; v != a;) {
      int l = gr[v][prev[v]].v;
      int r = gr[v][prev[v]].rev;
      gr[l][r].flow += add;
      gr[v][prev[v]].flow -= add;
      cost += gr[l][r].cost * add;
      v = l;
    }
    flow += add;
  }
  cout << cost * -1 << endl;
  vector<int> used_in_ans(113, 0);
  for (int v = 1; v <= k; ++v) {
    for (auto u : gr[v]) {
      if (u.flow == 1) {
        assert(used_in_ans[u.v - 53] != 1);
        cout << itoc(u.v - 53);
        used_in_ans[u.v - 53] = 1;
        break;
      }
    }
  }
  return 0;
}
