#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int m, n, N;
char a[3000000], b[3000000];
int cnt[60][60];
map<char, int> mp, xmp;
struct EDGE {
  int s, e, f, x, r;
  EDGE() {}
  EDGE(int s, int e, int f, int x, int r) {
    this->s = s, this->e = e, this->f = f, this->x = x, this->r = r;
  }
} edges[100000];
int edgei;
vector<int> edge[1000];
int suc;
void addedge(int s, int e, int f, int x) {
  edges[edgei] = EDGE(s, e, f, x, edgei + 1);
  edges[edgei + 1] = EDGE(e, s, 0, -x, edgei);
  edgei += 2;
}
int d[1000];
int p[1000];
vector<int> path;
int dab[1000];
int main() {
  int i, j, k;
  scanf("%d%d", &m, &n);
  scanf("%s%s", a, b);
  for (i = 0; i < min(n, 26); i++) mp['a' + i] = i, xmp[i] = 'a' + i;
  for (i = 26; i < n; i++) mp['A' + i - 26] = i, xmp[i] = 'A' + i - 26;
  for (i = 0; i < m; i++) {
    cnt[mp[a[i]]][mp[b[i]]]++;
  }
  for (i = 0; i < n; i++) {
    addedge(0, i + 1, 1, 0);
    addedge(n + 1 + i, 2 * n + 1, 1, 0);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      addedge(i + 1, j + n + 1, 1, -cnt[i][j]);
    }
  }
  N = 2 * n + 2;
  int xdab = 0;
  for (k = 0; k < n; k++) {
    path.clear();
    fill(d, d + N, ((1 << 30) - 1));
    d[0] = 0, p[0] = -1;
    for (i = 0; i < N; i++) {
      for (j = 0; j < edgei; j++) {
        EDGE now = edges[j];
        if (now.f == 0) continue;
        if (d[now.e] > d[now.s] + now.x) {
          d[now.e] = d[now.s] + now.x;
          p[now.e] = j;
        }
      }
    }
    xdab += d[N - 1];
    int now = N - 1;
    while (now != 0) {
      path.push_back(p[now]);
      now = edges[p[now]].s;
    }
    for (i = path.size() - 1; i >= 0; i--) {
      int nowedge = path[i];
      edges[edges[nowedge].r].f += edges[nowedge].f;
      edges[nowedge].f = 0;
    }
  }
  for (i = 0; i < edgei; i++) {
    if (edges[i].s != 0 && edges[i].e != 0 && edges[i].s < edges[i].e &&
        edges[i].f == 0) {
      dab[edges[i].s - 1] = edges[i].e - n - 1;
    }
  }
  printf("%d\n", -xdab);
  for (i = 0; i < n; i++) printf("%c", xmp[dab[i]]);
  return 0;
}
