#include <bits/stdc++.h>
using namespace std;
const int inf = 1000100100;
const int maxn = 210;
int n;
string sa, sb;
int arr[52][52];
int toi(char c) {
  if (c >= 'a') return c - 'a';
  return c - 'A' + 26;
}
char toc(int i) {
  if (i < 26) return i + 'a';
  return i - 26 + 'A';
}
int vala[maxn], valb[maxn];
int visa[maxn], visb[maxn];
int rev[maxn];
bool dfs(int a) {
  visa[a] = true;
  for (int b = 0; b < n; b++) {
    if (!visb[b] && vala[a] + valb[b] == arr[a][b]) {
      visb[b] = true;
      if (rev[b] == -1 || dfs(rev[b])) {
        rev[b] = a;
        return true;
      }
    }
  }
  return false;
}
void go() {
  for (int i = 0; i < n; i++) {
    vala[i] = -inf;
    for (int j = 0; j < n; j++) {
      vala[i] = max(vala[i], arr[i][j]);
    }
    valb[i] = 0;
  }
  memset(rev, -1, sizeof(rev));
  for (int i = 0; i < n; i++) {
    while (true) {
      memset(visa, 0, sizeof(visa));
      memset(visb, 0, sizeof(visb));
      if (dfs(i)) break;
      int diff = inf;
      for (int a = 0; a < n; a++) {
        if (visa[a]) {
          for (int b = 0; b < n; b++) {
            if (!visb[b]) {
              diff = min(diff, vala[a] + valb[b] - arr[a][b]);
            }
          }
        }
      }
      for (int i = 0; i < n; i++) {
        if (visa[i]) vala[i] -= diff;
        if (visb[i]) valb[i] += diff;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += arr[rev[i]][i];
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    cout << toc(rev[i]);
  }
}
int main() {
  int m;
  cin >> m >> n;
  cin >> sa >> sb;
  for (int i = 0; i < m; i++) {
    arr[toi(sb[i])][toi(sa[i])]++;
  }
  go();
}
