#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& _p) {
  return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& _V) {
  bool f = true;
  os << "[";
  for (auto v : _V) {
    os << (f ? "" : ",") << v;
    f = false;
  }
  return os << "]";
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& _S) {
  bool f = true;
  os << "(";
  for (auto s : _S) {
    os << (f ? "" : ",") << s;
    f = false;
  }
  return os << ")";
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& _M) {
  return os << set<pair<T, U>>(_M.begin(), _M.end());
}
const signed long long INF = 1000000100;
const long double EPS = 1e-9;
const int MAXN = 100;
int n1, n2;
int weight[MAXN][MAXN];
int mate1[MAXN], mate2[MAXN];
int old_dist1[MAXN], dist1[MAXN], dist2[MAXN], prev2[MAXN];
int compute_bwm() {
  for (int(a) = (0); (a) < (n1); (a)++) {
    mate1[a] = -1;
    old_dist1[a] = 0;
  }
  for (int(b) = (0); (b) < (n2); (b)++) {
    mate2[b] = -1;
    dist2[b] = INF;
    for (int(a) = (0); (a) < (n1); (a)++)
      if (weight[a][b] < dist2[b]) {
        dist2[b] = weight[a][b];
        prev2[b] = a;
      }
  }
  int res = 0;
  for (;;) {
    int cur, min_dist = INF;
    for (int(b) = (0); (b) < (n2); (b)++)
      if (mate2[b] == -1 && dist2[b] < min_dist) {
        cur = b;
        min_dist = dist2[b];
      }
    if (min_dist == INF) break;
    res += min_dist;
    while (cur != -1) {
      int next = mate1[prev2[cur]];
      mate2[cur] = prev2[cur];
      mate1[prev2[cur]] = cur;
      cur = next;
    }
    for (int(a) = (0); (a) < (n1); (a)++) dist1[a] = mate1[a] == -1 ? 0 : INF;
    for (int(b) = (0); (b) < (n2); (b)++) dist2[b] = INF;
    for (;;) {
      min_dist = INF;
      for (int(a) = (0); (a) < (n1); (a)++)
        if (dist1[a] != INF && dist1[a] - old_dist1[a] < min_dist) {
          cur = a;
          min_dist = dist1[a] - old_dist1[a];
        }
      if (min_dist == INF) break;
      for (int(b) = (0); (b) < (n2); (b)++)
        if (b != mate1[cur] && weight[cur][b] != INF &&
            dist1[cur] + weight[cur][b] < dist2[b]) {
          dist2[b] = dist1[cur] + weight[cur][b];
          prev2[b] = cur;
          if (mate2[b] != -1) dist1[mate2[b]] = dist2[b] - weight[mate2[b]][b];
        }
      old_dist1[cur] = dist1[cur];
      dist1[cur] = INF;
    }
  }
  return res;
}
int N, M;
string A, B;
void read_data() { cin >> N >> M >> A >> B; }
int decode(int c) { return 'a' <= c and c <= 'z' ? c - 'a' : c - 'A' + 26; }
int encode(int c) { return c <= 25 ? c + 'a' : c - 26 + 'A'; }
void solve() {
  for (char& a : A) a = decode(a);
  for (char& b : B) b = decode(b);
  n1 = n2 = M;
  for (int(i) = (0); (i) < (M); (i)++)
    for (int(j) = (0); (j) < (M); (j)++) weight[i][j] = 0;
  for (int(i) = (0); (i) < (N); (i)++) weight[A[i]][B[i]]--;
  cout << -compute_bwm() << endl;
  for (int(i) = (0); (i) < (M); (i)++) cout << char(encode(mate1[i]));
  cout << endl;
}
int main() {
  read_data();
  solve();
}
