#include <bits/stdc++.h>
int main(void) {
  int i, n, j, t, k, minj, A[100], fmin;
  int count = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  for (i = 0; i < n; i++) {
    minj = i;
    fmin = minj;
    for (j = i; j < n; j++) {
      if (A[j] < A[minj]) minj = j;
    }
    t = A[i];
    A[i] = A[minj];
    A[minj] = t;
    if (fmin != minj) count++;
    for (k = 0; k < n - 1; k++) printf("%d ", A[k]);
    printf("%d\n", A[k]);
  }
  printf("%d\n", count);
  return 0;
}
