#include <bits/stdc++.h>
using namespace std;
int n, k;
string s1, s2;
int a[53][53];
char to[53];
int id(char q) {
  if (q >= 'a')
    return (int)q - 'a' + 1;
  else
    return (int)q - 'A' + 27;
}
char get(int q) {
  if (q >= 27)
    return (char)'A' + (q - 27);
  else
    return (char)'a' + (q - 1);
}
int main() {
  cin >> n >> k >> s1 >> s2;
  for (int i = 0; i < n; ++i) --a[id(s1[i])][id(s2[i])];
  vector<int> u(k + 1), v(k + 1), p(k + 1), way(k + 1);
  for (int i = 1; i <= k; ++i) {
    p[0] = i;
    int j0 = 0;
    vector<int> minv(k + 1, INT_MAX);
    vector<char> used(k + 1, false);
    do {
      used[j0] = true;
      int i0 = p[j0], delta = INT_MAX, j1;
      for (int j = 1; j <= k; ++j)
        if (!used[j]) {
          int cur = a[i0][j] - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (int j = 0; j <= k; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      int j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
  }
  cout << v[0] << '\n';
  for (int j = 1; j <= k; ++j) to[p[j]] = get(j);
  for (int i = 1; i <= k; ++i) cout << to[i];
}
