#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a[210000], i, t1 = 0, t2 = 0, j, b[210000], c[1000], p = 1, x,
                                y, z, l1, l2, t, count = 0, temp, l, r, mid;
  scanf("%lld %lld", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (i < k + 1) {
      b[i] = 0;
      c[i] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    sort(c + 1, c + p + 1);
    l = 1;
    r = p;
    while (l <= r) {
      mid = (l + r) / 2;
      if (c[mid] == a[i]) {
        t1 = 1;
        break;
      }
      if (c[mid] < a[i])
        l = mid + 1;
      else
        r = mid - 1;
    }
    if (t1 == 0) {
      if (p > 1) {
        for (x = p; x > 1; x--) {
          b[x] = b[x - 1];
          c[x] = b[x];
        }
      }
      b[1] = a[i];
      c[1] = a[i];
      if (p < k) p++;
    }
    t1 = 0;
  }
  for (x = 1; x <= p; x++) {
    if (b[x] > 0) count++;
  }
  printf("%lld\n", count);
  for (x = 1; x <= count; x++) {
    printf("%lld ", b[x]);
  }
  return 0;
}
