import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto mn = new int[Q + 1];
      auto mx = new int[Q + 1];
      mn[] = N;
      mx[] = -1;
      foreach (i; 0 .. N) {
        chmin(mn[A[i]], i);
        chmax(mx[A[i]], i);
      }

      bool ans = false;
      auto as = A.dup;

      int inner;
      foreach (i; 0 .. N) {
        if (A[i] != 0) {
          inner = A[i];
          break;
        }
      }
      if (inner == 0) {
        inner = Q;
      }
      DList!int stack;
      foreach (i; 0 .. N) {
        if (A[i] == 0) {
          as[i] = inner;
        } else {
          if (mn[A[i]] == i) {
            if (!stack.empty && stack.back >= A[i]) {
              debug {
                writeln("incorrect order");
              }
              goto failed;
            }
            stack ~= A[i];
            inner = stack.back;
          }
          if (stack.empty || stack.back != A[i]) {
            debug {
              writeln("not top");
            }
            goto failed;
          }
          if (mx[A[i]] == i) {
            stack.removeBack;
            if (!stack.empty) {
              inner = stack.back;
            }
          }
        }
      }
      if (as.count(Q) == 0) {
        if (A.count(0) == 0) {
          debug {
            writeln("place for Q not found");
          }
          goto failed;
        } else {
          foreach (i; 0 .. N) {
            if (A[i] == 0) {
              as[i] = Q;
              break;
            }
          }
        }
      }
      ans = true;
     failed:

      if (ans) {
        writeln("YES");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(as[i]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = A.dup;

    if (A.map!(a => a == 0).all) {
        writeln("YES");
        fill(B, Q);
        B.map!(to!string).join(" ").writeln;
        return;
    }

    auto next = iota(1, N+1).array;
    auto prev = iota(-1, N-1).array;

    auto LR = new int[][](Q+1, 2);
    foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;

    foreach (i; 0..N) {
        LR[A[i]][0] = min(LR[A[i]][0], i);
        LR[A[i]][1] = max(LR[A[i]][1], i);
    }

    foreach_reverse (i; 1..Q+1) {
        if (LR[i][0] == INF) continue;
        for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {
            if (A[j] != 0 && A[j] < i) {
                writeln("NO");
                return;
            } else if (B[j] == 0) {
                B[j] = i;
            }
        }

        if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];
        if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];
    }

    foreach (i; 0..N) if (B[i] == 0) B[i] = 1;

    if (LR[Q][0] == INF) {
        bool ok = false;
        foreach (i; 0..N) {
            if (A[i] == 0) {
                B[i] = Q;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
    B.map!(to!string).join(" ").writeln;
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    int fstzro = arr.canFind(0) ? n - arr.find(0).length.to!int : -1;
    foreach (i; 0 .. n) {
        if (arr[i] == 0 && i > 0 && arr[i-1] != 0) {
            arr[i] = arr[i-1];
        }
    }
    foreach_reverse (i; 0 .. n) {
        if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];
    }
    foreach (i; 0 .. n) {
        if (arr[i] == 0) arr[i] = q;
    }

    debug { arr.writeln; }

    if (!arr.canFind(q)) {
        if (fstzro != -1) {
            arr[fstzro] = q;
        } else {
            writeln("NO");
            return;
        }
    }

    immutable int MAX_IDX = q;
    int[] fw = new int[] (MAX_IDX+1);
    void add(int idx, int v) {
        while (idx <= MAX_IDX) {
            fw[idx] = v;
            idx += (idx & -idx);
        }
    }

    int get(int idx) {
        int mx = -1;
        while (idx > 0) {
            mx = max(mx, fw[idx]);
            idx -= (idx & -idx);
        }
        return mx;
    }

    int[] lst = new int[] (MAX_IDX+1);
    lst[] = -1;
    foreach (i, e; arr) {
        if (lst[e] != -1 && lst[e] < get(e-1)) {
            writeln("NO");
            return;
        }
        lst[e] = cast(int) i;
        add(e, cast(int) i);
    }

    writeln("YES");
    arr.writefln!("%(%s %)");
}

// same submission to check against added tests
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int logHalf = 18;
immutable int half = 1 << logHalf;
immutable int limit = half << 1;

void main ()
{
	int n, q;
multitest_loop:
	while (readf (" %s %s", &n, &q) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;

		auto lo = new int [q + 1];
		lo[] = int.max;
		auto hi = new int [q + 1];
		hi[] = int.min;
		int pos0 = -1;
		foreach (i, c; a)
		{
			if (c != 0)
			{
				lo[c] = min (lo[c], i);
				hi[c] = max (hi[c], i);
			}
			else
			{
				pos0 = i;
			}
		}
		if (lo[q] == int.max)
		{
			if (pos0 == -1)
			{
				writeln ("NO");
				continue multitest_loop;
			}
			else
			{
				lo[q] = pos0;
				hi[q] = pos0;
			}
		}

		foreach (j; 1..q)
		{
			if (lo[j] == int.max)
			{
				lo[j] = lo[q];
				hi[j] = hi[q];
			}
		}
		lo[1] = 0;
		hi[1] = n - 1;

		auto t = new int [limit];

		void tFill (int u, int v, int w)
		{
			for (u += half, v += half; u < v; u >>= 1, v >>= 1)
			{
				if (u & 1)
				{
					t[u] = w;
					u += 1;
				}
				if (v & 1)
				{
					v -= 1;
					t[v] = w;
				}
			}
		}

		int tGet (int u)
		{
			int res = 0;
			for (u += half; u > 0; u >>= 1)
			{
				res = max (res, t[u]);
			}
			return res;
		}

		foreach (j; 1..q + 1)
		{
			tFill (lo[j], hi[j] + 1, j);
		}

		auto b = n.iota.map !(i => tGet (i)).array;
		debug {writeln (b);}
		foreach (i; 0..n)
		{
			if (a[i] != 0 && a[i] != b[i])
			{
				writeln ("NO");
				continue multitest_loop;
			}
		}

		writeln ("YES");
		writefln ("%(%s %)", b);
	}
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
        if (!t[v])
            t[v] = int.max;
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    if (!a.count(m)) {
        bool ok = false;
        foreach (ref val; a) {
            if (!val) {
                val = m;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            a[c .. i] = a[c - 1];
        }
    }
    writefln("YES\n%(%d %)", a);
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = A.dup;

    if (A.map!(a => a == 0).all) {
        writeln("YES");
        fill(B, Q);
        B.map!(to!string).join(" ").writeln;
        return;
    }

    auto next = iota(1, N+1).array;
    auto prev = iota(-1, N-1).array;

    auto LR = new int[][](Q+1, 2);
    foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;

    foreach (i; 0..N) {
        LR[A[i]][0] = min(LR[A[i]][0], i);
        LR[A[i]][1] = max(LR[A[i]][1], i);
    }

    foreach_reverse (i; 1..Q+1) {
        if (LR[i][0] == INF) continue;
        for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {
            if (A[j] != 0 && A[j] < i) {
                writeln("NO");
                return;
            } else if (A[j] == 0) {
                B[j] = i;
            }
        }
        for (int j = prev[LR[i][0]]; j >= 0 && B[j] == 0; j = prev[j]) {
            B[j] = i;
            LR[i][0] = j;
        }
        for (int j = next[LR[i][1]]; j < N && B[j] == 0; j = next[j]) {
            B[j] = i;
            LR[i][1] = j;
        }

        if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];
        if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];
    }

    if (LR[Q][0] == INF) {
        bool ok = false;
        foreach (i; 0..N) {
            if (A[i] == 0) {
                B[i] = Q;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
    B.map!(to!string).join(" ").writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = A.dup;

    if (A.map!(a => a == 0).all) {
        writeln("YES");
        fill(B, Q);
        B.map!(to!string).join(" ").writeln;
        return;
    }

    auto next = iota(1, N+1).array;
    auto prev = iota(-1, N-1).array;

    auto LR = new int[][](Q+1, 2);
    foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;

    foreach (i; 0..N) {
        LR[A[i]][0] = min(LR[A[i]][0], i);
        LR[A[i]][1] = max(LR[A[i]][1], i);
    }

    foreach_reverse (i; 1..Q+1) {
        if (LR[i][0] == INF) continue;
        for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {
            if (A[j] != 0 && A[j] < i) {
                writeln("NO");
                return;
            } else if (A[j] == 0) {
                B[j] = i;
            }
        }

        if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];
        if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];
    }

    foreach (i; 0..N) if (B[i] == 0) B[i] = 1;

    if (LR[Q][0] == INF) {
        bool ok = false;
        foreach (i; 0..N) {
            if (A[i] == 0) {
                B[i] = Q;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
    B.map!(to!string).join(" ").write;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = A.dup;

    if (A.map!(a => a == 0).all) {
        writeln("YES");
        fill(B, Q);
        B.map!(to!string).join(" ").writeln;
        return;
    }

    auto next = iota(1, N+1).array;
    auto prev = iota(-1, N-1).array;

    auto LR = new int[][](Q+1, 2);
    foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;

    foreach (i; 0..N) {
        LR[A[i]][0] = min(LR[A[i]][0], i);
        LR[A[i]][1] = max(LR[A[i]][1], i);
    }

    foreach_reverse (i; 1..Q+1) {
        if (LR[i][0] == INF) continue;
        for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {
            if (A[j] != 0 && A[j] < i) {
                writeln("NO");
                return;
            } else if (A[j] == 0) {
                B[j] = i;
            }
        }

        if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];
        if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];
    }

    foreach (i; 0..N) if (B[i] == 0) B[i] = 1;

    if (LR[Q][0] == INF) {
        bool ok = false;
        foreach (i; 0..N) {
            if (A[i] == 0) {
                B[i] = Q;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
    B.map!(to!string).join(" ").writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = A.dup;

    if (A.map!(a => a == 0).all) {
        writeln("YES");
        fill(B, Q);
        B.map!(to!string).join(" ").writeln;
        return;
    }

    auto next = iota(1, N+1).array;
    auto prev = iota(-1, N-1).array;

    auto LR = new int[][](Q+1, 2);
    foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;

    foreach (i; 0..N) {
        LR[A[i]][0] = min(LR[A[i]][0], i);
        LR[A[i]][1] = max(LR[A[i]][1], i);
    }

    foreach_reverse (i; 1..Q+1) {
        if (LR[i][0] == INF) continue;
        for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {
            if (A[j] != 0 && A[j] < i) {
                writeln("NO");
                return;
            } else if (A[j] == 0) {
                B[j] = i;
            }
        }
        for (int j = prev[LR[i][0]]; j >= 0 && B[j] == 0; j = prev[j]) {
            B[j] = i;
        }
        for (int j = next[LR[i][1]]; j < N && B[j] == 0; j = next[j]) {
            B[j] = i;
        }

        if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];
        if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];
    }

    if (LR[Q][0] == INF) {
        bool ok = false;
        foreach (i; 0..N) {
            if (A[i] == 0) {
                B[i] = Q;
                ok = true;
                break;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }

    writeln("YES");
    B.map!(to!string).join(" ").writeln;
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    foreach (i; 0 .. n) {
        if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];
    }
    foreach_reverse (i; 0 .. n) {
        if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];
    }
    foreach (i; 0 .. n) {
        if (arr[i] == 0) arr[i] = q;
    }

    debug { arr.writeln; }

    if (!arr.canFind(q)) {
        writeln("NO");
        return;
    }

    immutable int MAX_IDX = q;
    int[] fw = new int[] (MAX_IDX+1);
    void add(int idx, int v) {
        while (idx <= MAX_IDX) {
            fw[idx] = v;
            idx += (idx & -idx);
        }
    }

    int get(int idx) {
        int mx = -1;
        while (idx > 0) {
            mx = max(mx, fw[idx]);
            idx -= (idx & -idx);
        }
        return mx;
    }

    int[] lst = new int[] (MAX_IDX+1);
    lst[] = -1;
    foreach (i, e; arr) {
        if (lst[e] != -1 && lst[e] < get(e-1)) {
            writeln(i, ' ', e, ' ', lst[e], ' ', get(e-1));
            writeln("NO");
            return;
        }
        lst[e] = cast(int) i;
        add(e, cast(int) i);
    }

    writeln("YES");
    arr.writefln!("%(%s %)");
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    foreach (i; 0 .. n) {
        if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];
    }
    foreach_reverse (i; 0 .. n) {
        if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];
    }
    foreach (i; 0 .. n) {
        if (arr[i] == 0) arr[i] = q;
    }

    debug { arr.writeln; }

    immutable int MAX_IDX = q;
    int[] fw = new int[] (MAX_IDX+1);
    void add(int idx, int v) {
        while (idx <= MAX_IDX) {
            fw[idx] = v;
            idx += (idx & -idx);
        }
    }

    int get(int idx) {
        int mx = -1;
        while (idx > 0) {
            mx = max(mx, fw[idx]);
            idx -= (idx & -idx);
        }
        return mx;
    }

    int[] lst = new int[] (MAX_IDX+1);
    lst[] = -1;
    foreach (i, e; arr) {
        if (lst[e] != -1 && lst[e] < get(e-1)) {
            writeln(i, ' ', e, ' ', lst[e], ' ', get(e-1));
            writeln("NO");
            return;
        }
        lst[e] = cast(int) i;
        add(e, cast(int) i);
    }

    writeln("YES");
    arr.writefln!("%(%s %)");
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    foreach (i; 0 .. n) {
        if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];
    }
    foreach_reverse (i; 0 .. n) {
        if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];
    }
    foreach (i; 0 .. n) {
        if (arr[i] == 0) arr[i] = q;
    }

    debug { arr.writeln; }

    if (!arr.canFind(q)) {
        writeln("NO");
        return;
    }

    immutable int MAX_IDX = q;
    int[] fw = new int[] (MAX_IDX+1);
    void add(int idx, int v) {
        while (idx <= MAX_IDX) {
            fw[idx] = v;
            idx += (idx & -idx);
        }
    }

    int get(int idx) {
        int mx = -1;
        while (idx > 0) {
            mx = max(mx, fw[idx]);
            idx -= (idx & -idx);
        }
        return mx;
    }

    int[] lst = new int[] (MAX_IDX+1);
    lst[] = -1;
    foreach (i, e; arr) {
        if (lst[e] != -1 && lst[e] < get(e-1)) {
            writeln("NO");
            return;
        }
        lst[e] = cast(int) i;
        add(e, cast(int) i);
    }

    writeln("YES");
    arr.writefln!("%(%s %)");
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            writeln(i);
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            writeln(i);
            a[c .. i] = a[c - 1];
        }
    }
    writefln("YES\n%(%d %)", a);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
        if (!t[v])
            t[v] = int.max;
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    if (!a.count(m)) {
        bool ok = false;
        foreach (ref val; a) {
            if (!val) {
                val = m;
                ok = true;
            }
        }
        if (!ok) {
            writeln("NO");
            return;
        }
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            a[c .. i] = a[c - 1];
        }
    }
    writefln("YES\n%(%d %)", a);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            a[c .. i] = a[c - 1];
        }
    }
    writefln("YES\n%(%d %)", a);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
        if (!t[v])
            t[v] = int.max;
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    if (!a.count(0) && !a.count(m)) {
        writeln("NO");
        return;
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            a[c .. i] = a[c - 1];
        }
    }
    writefln("YES\n%(%d %)", a);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
import std.string;

struct seg
{
    int l = int.max;
    int r;
}

int[] t;
void build(int[] a, int v)
{
    if (a.length == 1) {
        t[v] = a[0];
    }
    else {
        int mid = cast(int)a.length >> 1;
        build(a[0 .. mid], v * 2 + 1);
        build(a[mid .. $], v * 2 + 2);
        t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
    }
}

int get(int v, int ql, int qr, int l, int r)
{
    if (l == ql && r == qr)
        return t[v];
    int mid = (l + r) / 2;
    if (qr <= mid)
        return get(v * 2 + 1, ql, qr, l, mid);
    if (ql >= mid)
        return get(v * 2 + 2, ql, qr, mid, r);
    int t1 = get(v * 2 + 1, ql, mid, l, mid);
    int t2 = get(v * 2 + 2, mid, qr, mid, r);
    return min(t1, t2);
}

void main()
{
    int n, m;
    readf("%d %d\n", &n, &m);
    auto a = readln.splitter.map!(to!int).array;
    t = new int[n * 4];
    build(a, 0);
    auto b = new seg[m];
    foreach (int i, val; a) {
        if (!val)
            continue;
        --val;
        b[val].l = min(b[val].l, i);
        b[val].r = max(b[val].r, i);
    }
    foreach (i, ref sg; b) {
        if (sg.l != int.max
            && get(0, sg.l, sg.r + 1, 0, n) <= i) {
            writeln("NO");
            return;
        }
    }
    if (a.count(0) == a.length)
        a[] = m;
    else {
        int i;
        while (!a[i])
            ++i;
        a[0 .. i] = a[i];
        while (i < a.length) {
            if (a[i]) {
                ++i;
                continue;
            }
            writeln(i);
            int c = i;
            while (i < a.length && !a[i])
                ++i;
            writeln(i);
            a[c .. i] = a[c - 1];
        }
    }
    writefln("%(%d %)", a);
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto mn = new int[Q + 1];
      auto mx = new int[Q + 1];
      mn[] = N;
      mx[] = -1;
      foreach (i; 0 .. N) {
        chmin(mn[A[i]], i);
        chmax(mx[A[i]], i);
      }

      auto diss = new int[][N];
      auto fins = new int[][N];
      foreach (j; 1 .. Q + 1) {
        if (mn[j] <= mx[j]) {
          diss[mn[j]] ~= j;
          fins[mx[j]] ~= j;
        }
      }
      foreach (i; 0 .. N) {
        diss[i].sort!((j0, j1) => (j0 < j1));
        fins[i].sort!((j0, j1) => (j0 > j1));
      }
      debug {
        writeln("diss = ", diss);
        writeln("fins = ", fins);
      }

      bool ans = false;
      auto as = A.dup;

      int outer;
      foreach (i; 0 .. N) {
        if (diss[i]) {
          outer = diss[i][0];
          break;
        }
      }
      if (outer == 0) {
        outer = Q;
      }
      DList!int stack;
      foreach (i; 0 .. N) {
        if (A[i] == 0) {
          as[i] = outer;
        } else {
          foreach (j; diss[i]) {
            if (!stack.empty && stack.back >= j) {
              goto failed;
            }
            if (stack.empty) {
              outer = j;
            }
            stack ~= j;
          }
          if (stack.empty || stack.back != A[i]) {
            goto failed;
          }
          foreach (j; fins[i]) {
            if (stack.empty || stack.back != j) {
              goto failed;
            }
            stack.removeBack;
          }
        }
      }
      if (as.count(Q) == 0) {
        if (A.count(0) == 0) {
          goto failed;
        } else {
          foreach (i; 0 .. N) {
            if (A[i] == 0) {
              as[i] = Q;
              break;
            }
          }
        }
      }
      ans = true;
     failed:
      if (ans) {
        writeln("YES");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(as[i]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto mn = new int[Q + 1];
      auto mx = new int[Q + 1];
      mn[] = N;
      mx[] = -1;
      foreach (i; 0 .. N) {
        chmin(mn[A[i]], i);
        chmax(mx[A[i]], i);
      }

      auto diss = new int[][N];
      auto fins = new int[][N];
      foreach (j; 1 .. Q + 1) {
        if (mn[j] <= mx[j]) {
          diss[mn[j]] ~= j;
          fins[mx[j]] ~= j;
        }
      }
      foreach (i; 0 .. N) {
        diss[i].sort!((j0, j1) => (j0 < j1));
        fins[i].sort!((j0, j1) => (j0 > j1));
      }
      debug {
        writeln("diss = ", diss);
        writeln("fins = ", fins);
      }

      bool ans = false;
      auto as = A.dup;

      int outer;
      foreach (i; 0 .. N) {
        if (diss[i]) {
          outer = diss[i][0];
          break;
        }
      }
      if (outer == 0) {
        outer = Q;
      }
      DList!int stack;
      foreach (i; 0 .. N) {
        if (A[i] == 0) {
          as[i] = outer;
        } else {
          foreach (j; diss[i]) {
            if (!stack.empty && stack.back >= j) {
              goto failed;
            }
            if (stack.empty) {
              outer = j;
            }
            stack ~= j;
          }
          foreach (j; fins[i]) {
            if (stack.empty || stack.back != j) {
              goto failed;
            }
            stack.removeBack;
          }
        }
      }
      if (as.count(Q) == 0) {
        if (A.count(0) == 0) {
          goto failed;
        } else {
          foreach (i; 0 .. N) {
            if (A[i] == 0) {
              as[i] = Q;
              break;
            }
          }
        }
      }
      ans = true;
     failed:
      if (ans) {
        writeln("YES");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(as[i]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto mn = new int[Q + 1];
      auto mx = new int[Q + 1];
      mn[] = N;
      mx[] = -1;
      foreach (i; 0 .. N) {
        chmin(mn[A[i]], i);
        chmax(mx[A[i]], i);
      }

      auto diss = new int[][N];
      auto fins = new int[][N];
      foreach (j; 1 .. Q + 1) {
        if (mn[j] <= mx[j]) {
          diss[mn[j]] ~= j;
          fins[mx[j]] ~= j;
        }
      }
      foreach (i; 0 .. N) {
        diss[i].sort!((j0, j1) => (j0 < j1));
        fins[i].sort!((j0, j1) => (j0 > j1));
      }
      debug {
        writeln("diss = ", diss);
        writeln("fins = ", fins);
      }

      int outer;
      foreach (i; 0 .. N) {
        if (diss[i]) {
          outer = diss[i][0];
          break;
        }
      }
      if (outer == 0) {
        outer = 1;
      }
      auto as = A.dup;
      DList!int stack;
      bool ans = false;
      foreach (i; 0 .. N) {
        if (A[i] == 0) {
          as[i] = outer;
        } else {
          foreach (j; diss[i]) {
            if (!stack.empty && stack.back >= j) {
              goto failed;
            }
            if (stack.empty) {
              outer = j;
            }
            stack ~= j;
          }
          foreach (j; fins[i]) {
            if (stack.empty || stack.back != j) {
              goto failed;
            }
            stack.removeBack;
          }
        }
      }
      ans = true;
     failed:
      if (ans) {
        writeln("YES");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(as[i]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto mn = new int[Q + 1];
      auto mx = new int[Q + 1];
      mn[] = N;
      mx[] = -1;
      foreach (i; 0 .. N) {
        chmin(mn[A[i]], i);
        chmax(mx[A[i]], i);
      }

      bool ans = false;
      auto as = A.dup;

      int outer;
      foreach (i; 0 .. N) {
        if (A[i] != 0) {
          outer = A[i];
          break;
        }
      }
      if (outer == 0) {
        outer = Q;
      }
      DList!int stack;
      foreach (i; 0 .. N) {
        if (A[i] == 0) {
          as[i] = outer;
        } else {
          if (mn[A[i]] == i) {
            if (!stack.empty && stack.back >= A[i]) {
              debug {
                writeln("incorrect order");
              }
              goto failed;
            }
            if (stack.empty) {
              outer = A[i];
            }
            stack ~= A[i];
          }
          if (stack.empty || stack.back != A[i]) {
            debug {
              writeln("not top");
            }
            goto failed;
          }
          if (mx[A[i]] == i) {
            stack.removeBack;
          }
        }
      }
      if (as.count(Q) == 0) {
        if (A.count(0) == 0) {
          debug {
            writeln("place for Q not found");
          }
          goto failed;
        } else {
          foreach (i; 0 .. N) {
            if (A[i] == 0) {
              as[i] = Q;
              break;
            }
          }
        }
      }
      ans = true;
     failed:

      if (ans) {
        writeln("YES");
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(as[i]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }
        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int k = cin.read_int;

                int[] arr = new int[n];
                if (k == n) writeln(-1);
                else {
                        for (int i = n; i > n - k; i--) {
                                arr[i - 1] = i;
                        }
                        for (int i = 1; i < n - k; i++) {
                                arr[i - 1] = i + 1;
                        }
                        arr[n - k - 1] = 1;
                        foreach (i; arr) write(i, " ");
                }
        }
}

import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.bigint, std.math, std.range;
import core.thread;

//  Input
string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }

int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//  chmin/chmax
void chmin(T)(ref T t, T f) { if (t > f) t = f; }
void chmax(T)(ref T t, T f) { if (t < f) t = f; }

int N;
int K;

void main () {
     N = readInt();
     K = readInt();

     int i;

     if (N == K) {
        writeln("-1");
     } else if (N == K + 1) {
        for (i = 1; i <= N; i++) {
            writef("%s ", i);
        }
     } else {
        writef("%s ", N);

        for (i = 2; i <= K + 1; i++) {
            writef("%s ", i);
        }

        writef("%s ", 1);

        for (i = K + 2; i <= N - 1; i++) {
            writef("%s ", i);
        }
     }
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }
        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int k = cin.read_int;

                int[] arr = new int[n];
                for (int i = 1; i <= k; i++) {
                        if (i * 2 > n) {
                                writeln(-1);
                                return;
                        } else arr[i - 1] = i * 2;
                }

                for (int i = k + 1; i <= n; i++) {
                        if (canFind(arr, i)) {
                                for (int j = 1; j <= n; j++) {
                                        if(!canFind(arr, j)) arr[i - 1] = j;
                                        break;
                                }
                        } else arr[i - 1] = i;
                }

                foreach (i; arr) {
                        write(i, " ");
                }
        }
}


import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new string[M];
      foreach (x; 0 .. M) {
        A[x] = readToken();
      }

      auto uf = new int[M * N];
      uf[] = -1;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);
          if (y > 0 && A[x][y - 1] == '#') uf.connect(x * N + (y - 1), x * N + y);
        }
      }
      int num;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (uf[x * N + y] < 0) {
            ++num;
          }
        }
      }

      bool ans = true;
      bool empRow, empCol;
      foreach (x; 0 .. M) {
        int mn = N, mx = -1;
        foreach (y; 0 .. N) {
          if (A[x][y] == '#') {
            chmin(mn, y);
            chmax(mx, y);
          }
        }
        if (mn <= mx) {
          foreach (y; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empRow = true;
        }
      }
      foreach (y; 0 .. N) {
        int mn = M, mx = -1;
        foreach (x; 0 .. M) {
          if (A[x][y] == '#') {
            chmin(mn, x);
            chmax(mx, x);
          }
        }
        if (mn <= mx) {
          foreach (x; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empCol = true;
        }
      }
      ans = ans && (empRow == empCol);

      writeln(ans ? num : -1);
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;
immutable int dirs = 4;
immutable int [dirs] dRow = [-1,  0, +1,  0];
immutable int [dirs] dCol = [ 0, -1,  0, +1];

void main ()
{
	int rows, cols;
	while (readf !(" %s %s") (rows, cols) > 0)
	{
		readln;
		string [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.strip;
		}

		auto mark = new int [] [] (rows, cols);
		foreach (ref line; mark)
		{
			line[] = NA;
		}
		int num = 0;

		void doMark (int sRow, int sCol)
		{
			alias Coord = Tuple !(int, q{row}, int, q{col});
			Coord [] q;
			q ~= Coord (sRow, sCol);
			mark[sRow][sCol] = num;
			while (!q.empty)
			{
				auto row = q.front.row;
				auto col = q.front.col;
				q.popFront ();
				q.assumeSafeAppend ();
				foreach (dir; 0..dirs)
				{
					auto nRow = row + dRow[dir];
					auto nCol = col + dCol[dir];
					if (0 <= nRow && nRow < rows &&
					    0 <= nCol && nCol < cols &&
					    board[nRow][nCol] == '#' &&
					    mark[nRow][nCol] == NA)
					{
						mark[nRow][nCol] = num;
						q ~= Coord (nRow, nCol);
					}
				}
			}
		}

		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (board[row][col] == '#' &&
				    mark[row][col] == NA)
				{
					doMark (row, col);
					num += 1;
				}
			}
		}

		bool ok = true;

		auto countRow = new int [rows];
		auto countCol = new int [cols];
		foreach (row; 0..rows)
		{
			int temp = 0;
			foreach (col; 0..cols)
			{
				if (board[row][col] == '#')
				{
					countRow[row] += 1;
					countCol[col] += 1;
				}
			}
		}

		ok &= (countRow.canFind (0) == countCol.canFind (0));

		void checkSquare (ref int seen, int cur)
		{
			if (seen == NA)
			{
				seen = cur;
			}
			else if (seen < num)
			{
				if (cur == NA)
				{
					seen = num;
				}
				else if (cur != seen)
				{
					ok = false;
				}
			}
			else
			{
				if (cur != NA)
				{
					ok = false;
				}
			}
		}

		foreach (row; 0..rows)
		{
			int seen = NA;
			foreach (col; 0..cols)
			{
				auto cur = mark[row][col];
				checkSquare (seen, cur);
			}
		}
		foreach (col; 0..cols)
		{
			int seen = NA;
			foreach (row; 0..rows)
			{
				auto cur = mark[row][col];
				checkSquare (seen, cur);
			}
		}

		writeln (ok ? num : NA);
	}
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!int;
  auto m = next!int;
  auto imat = next!string(n);
  auto mat = new char[][](n, m);
  foreach(i; 0 .. n)
    mat[i][] = imat[i].dup;
  void impossible()
  {
    writeln(-1);
  }
  void ans(int a)
  {
    writeln(a);
  }
  int blankRows = 0;
  int blankCols = 0;
  foreach(i; 0 .. n)
    {
      int cnt = 0;
      int l = int.max;
      int h = int.min;
      foreach(j; 0 .. m)
	if (mat[i][j] == '#')
	  {
	    l = min(l, j);
	    h = max(h, j);
	    cnt++;
	  }
      if (cnt == 0)
	{
	  blankRows++;
	  continue;
	}
      if (h - l + 1 != cnt)
	return impossible;
    }
  foreach(i; 0 .. m)
    {
      int cnt = 0;
      int l = int.max;
      int h = int.min;
      foreach(j; 0 .. n)
	if (mat[j][i] == '#')
	  {
	    l = min(l, j);
	    h = max(h, j);
	    cnt++;
	  }
      if (cnt == 0)
	{
	  blankCols++;
	  continue;
	}
      if (h - l + 1 != cnt)
	return impossible;
    }
  if (blankRows != 0 && blankCols == 0
      || blankCols != 0 && blankRows == 0) return impossible;
  auto deltas = [[+1, 0], [-1, 0], [0, +1], [0, -1]];
  void dfs(int i, int j)
  {
    if (i < 0 || i >= n || j < 0 || j >= m || mat[i][j] != '#')
      return;
    assert(mat[i][j] == '#');
    mat[i][j] = '.';
    foreach(delta; deltas)
      dfs(i + delta[0], j + delta[1]);
  }
  int cmps = 0;
  foreach(i; 0 .. n)
    {
      foreach(j; 0 .. m)
	{
	  if (mat[i][j] == '#')
	    {
	      dfs(i, j);
	      cmps++;
	    }
	}
    }
  return ans(cmps);
}
ulong bitCnt(long x)
{
  ulong cnt = 0;
  while(x) {cnt += x & 1; x>>=1;}
  return cnt;
}
alias Arr(T) = Mat!(T, 1);
struct Mat(T, size_t dimension)
{
  T[] _baseArray;
  T[] _slice;
  size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}
  size_t[dimension] _indexer;
  this(T[] baseArray, size_t[dimension] sizes)
  {
    _baseArray = baseArray;
    _sizes = sizes;
    _indexer[dimension - 1] = 1;
    static foreach_reverse(i; 0 .. dimension - 1)
      _indexer[i] = _indexer[i + 1] * _sizes[i + 1];
    auto requiredSize = _indexer[0] * _sizes[0];
    debug assert(_baseArray.length >= requiredSize);
    _slice = _baseArray[0 .. requiredSize];
  }
  this(size_t[dimension] sizes)
  {
    size_t reqSize = 1;
    static foreach(i; 0 .. dimension)
      reqSize *= sizes[i];
    this(new T[](reqSize), sizes);
  }
  ref auto opIndex()
  {
    pragma(inline, true);
    return _slice[];
  }
  ref auto opIndex(I...)(I i)
  {
    pragma(inline, true);
    debug assert(i.length <= dimension);
    size_t index = mixin(iota(0, i.length).map!(j => text("i[", j, "]*_indexer[", j, "]")).join("+"));
    static if (i.length == dimension)
      {
	return _slice[index];
      }
    else
      {
	enum sliceDimension = dimension - i.length;
	size_t[sliceDimension] remSizes = _sizes[i.length .. $];
	auto basePortion = _slice[index .. index + _indexer[i.length - 1]];
 	return Mat!(T, sliceDimension)(basePortion, remSizes);
      }
  }
  static if (dimension == 2)
    {
      auto identity()
      {
	debug assert(dim(0) == dim(1));
	auto n = dim(0);
	auto id = Mat!(T, 2)([n, n]);
	foreach(k; 0 .. n)
	  id[k, k] = T(1);
	return id;
      }
      bool canMultiply(Mat!(T, 2) b)
      {
	return this.dim(1) == b.dim(0);
      }
      auto opBinary(string op)(Mat!(T, 2) b)
	if (op == "*")
	  {
	    debug assert(canMultiply(b));
	    auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);
	    foreach(i; 0 .. res.dim(0))
	      foreach(k; 0 .. this.dim(1))
		foreach(j; 0 .. res.dim(1))
		  res[i, j] = res[i, j] + this[i, k] * b[k, j];
	    return res;
	  }
      auto opBinary(string op)(ulong exp)
	if (op == "^^")
	  {
	    return this.pow(identity, exp);
	  }
      mixin interiorBinPow;
    }
}

struct Mod(T, ulong mod)
{
  alias This = Mod!(T, mod);
  T _rep; T rep() {return _rep;}
  this(W)(W w)
  {
    _rep = ((cast(T) w)%mod + mod) % mod;
  }
  static auto plainConstruct(T t)
  {
    pragma(inline, true);
    debug assert(t >= 0 && t < mod);
    auto res = Mod!(T, mod).init;
    res._rep = t;
    return res;
  }
  string toString()
  {
    return to!string(rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "*")
      {
	return This(_rep * b._rep);
      }
  }
}

mixin template interiorBinPow()
{
  alias ThisType = typeof(this);
  auto pow(ThisType res, ulong exp)
    {
      if (exp < 0) debug assert(0);
      auto pow = this;
      while(exp)
	{
	  if (exp & 1)
	    res = res * pow;
	  pow = pow * pow;
	  exp >>= 1;
	}
      return res;
    }
}

// INPUT
File inputFile;
DList!string _words;
void _wordsFill()
{
  while (_words.empty) _words.insertBack(inputFile.readln.split);
}
string popWord()
{
  _wordsFill;
  auto word = _words.front;
  _words.removeFront;
  return word;
}
string peekWord()
{
  _wordsFill;
  return _words.front;
}
T next(T)()
{
  return to!T(popWord);
}
T peek(T)()
{
  return to!T(peekWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto MAP = new char[][](N.to!size_t, M.to!size_t);
    foreach (i; 0..N) foreach (j, c; readln.chomp) MAP[i][j] = c;

    bool rb, cb;
    foreach (i; 0..N) {
        bool rrb = true;
        foreach (j; 0..M) if (MAP[i][j] == '#') {
            rrb = false;
            break;
        }
        if (rrb) {
            rb = true;
            break;
        }
    }
    foreach (j; 0..M) {
        bool ccb = true;
        foreach (i; 0..N) if (MAP[i][j] == '#') {
            ccb = false;
            break;
        }
        if (ccb) {
            cb = true;
            break;
        }
    }
    if (rb != cb) {
        writeln(-1);
        return;
    }

    foreach (i; 0..N) {
        bool cd;
        if (MAP[i][0] == '#') cd = true;
        foreach (j; 1..M) {
            if (MAP[i][j-1] == '.' && MAP[i][j] == '#') {
                if (cd) {
                    writeln(-1);
                    return;
                } else {
                    cd = true;
                }
            }
        }
    }
    foreach (j; 0..M) {
        bool cd;
        if (MAP[0][j] == '#') cd = true;
        foreach (i; 1..N) {
            if (MAP[i-1][j] == '.' && MAP[i][j] == '#') {
                if (cd) {
                    writeln(-1);
                    return;
                } else {
                    cd = true;
                }
            }
        }
    }
    auto cs = new int[][](N.to!size_t, M.to!size_t);
    int c;
    foreach (i; 0..N) foreach (j; 0..M) if (MAP[i][j] == '#' && cs[i][j] == 0) {
        void paint(int i, int j) {
            foreach (d; [[1,0], [0,1], [-1,0], [0,-1]]) {
                auto ii = i+d[0];
                auto jj = j+d[1];
                if (ii < 0 || ii >= N || jj < 0 || jj >= M || MAP[ii][jj] == '.' || cs[ii][jj] != 0) continue;
                cs[ii][jj] = c;
                paint(ii, jj);
            }
        }
        ++c;
        cs[i][j] = c;
        paint(i, j);
    }
    writeln(c);
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new string[M];
      foreach (x; 0 .. M) {
        A[x] = readToken();
      }

      auto uf = new int[M * N];
      uf[] = -1;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);
          if (y > 0 && A[x][y - 1] == '#') uf.connect(y * N + (y - 1), x * N + y);
        }
      }
      int num;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (uf[x * N + y] < 0) {
            ++num;
          }
        }
      }

      bool ans = true;
      bool empRow, empCol;
      foreach (x; 0 .. M) {
        int mn = N, mx = -1;
        foreach (y; 0 .. N) {
          if (A[x][y] == '#') {
            chmin(mn, y);
            chmax(mx, y);
          }
        }
        if (mn <= mx) {
          foreach (y; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empRow = true;
        }
      }
      foreach (y; 0 .. N) {
        int mn = M, mx = -1;
        foreach (x; 0 .. M) {
          if (A[x][y] == '#') {
            chmin(mn, x);
            chmax(mx, x);
          }
        }
        if (mn <= mx) {
          foreach (x; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empCol = true;
        }
      }
      ans = ans && (empRow == empCol);

      writeln(ans ? num : -1);
    }
  } catch (EOFException e) {
  }
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto T = readln.chomp.to!int;
    auto A = T.iota.map!(_ => readln.split.map!(to!long).array).array;

    foreach (i; 0..T) {
        auto a = A[i][0];
        auto b = A[i][1];
        auto e = A[i][2];
        if (a + e <= b) {
            writeln(0);
            continue;
        }
        long hi = e + 1;
        long lo = 0;
        while (hi - lo > 1) {
            auto mid = (hi + lo) / 2;
            if (a + e - mid > b + mid) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        writeln(lo + 1);
    }
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		long a = rint;
		long b = rint;
		long c = rint;

		long all = a + b + c;

		long l = all / 2 + 1 - a;
		if(l < 0) l = 0;

		if(l > c) "0".writeln;
		else (c - l + 1).writeln;
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto T = RD!int;
	auto ans = new long[](T);
	foreach (i; 0..T)
	{
		auto s = RD;
		auto t = RD;
		auto e = RD;

		auto a = (s + t + e) / 2 + 1;
		a      = max(a, s);
		ans[i] = (s+e) < a ? 0 : s + e - a + 1;
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush();
	debug readln();
}


import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

alias type = single;
static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }
struct TestCase
{
  mixin prettyPrinting;

  string s;

  void solve(long tc = -1)
  {
    logSym!(this);
    long[][char] indices = null;
    long[char] singleaps = null;
    long[string] pairaps = null;
    foreach(i, c; s)
      {
        indices[c] ~= cast(long) i;
        singleaps[c]++;
      }
    foreach(i, c; s)
      {
        foreach(w; 'a' .. cast(char)('z' + 1))
          {
            if (w in indices)
              {
                auto pairs = assumeSorted(indices[w])
                  .upperBound(i).length;
                if (pairs > 0)
                  {
                    char[] pair = [c, w];
                    pairaps.require(cast(string) pair, 0) += cast(int) pairs;
                  }
              }
          }
      }
    writeln(max(pairaps.byValue.fold!max(long.min),
                singleaps.byValue.fold!max(long.min)));
  }
}

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

void main() {
  auto s = readln.stripRight;
  int[26] c;
  long[26][26] d;
  foreach (ch; s) {
    int i = ch.to!int - 97;
    foreach (j; 0 .. 26) {
      d[j][i] += c[j];
    }
    ++c[i];
  }
  long res;
  foreach (i; 0 .. 26) {
    res = max (res, c[i]);
    foreach (j; 0 .. 26) res = max (res, d[i][j]);
  }
  writeln (res);
}

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max;

    IO io;
    string s = io.readToken;
    long[] cnt1 = new long[26];
    long[][] cnt2 = new long[][](26, 26);
    for (int i = 0; i < s.length; ++i) {
        int c = s[i] - 'a';
        for (int d = 0; d < 26; ++d) {
            cnt2[d][c] += cnt1[d];
        }
        cnt1[c]++;
    }
    long result = 0;
    for (int c = 0; c < 26; ++c) {
        result = max(result, cnt1[c]);
        for (int d = 0; d < 26; ++d) {
            result = max(result, cnt2[c][d]);
        }
    }
    writeln(result);
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto s = RD!string;
	auto cnt = new long[](26);
	auto ans = new long[][](26, 26);
	foreach (c; s)
	{
		auto i = c-'a';
		foreach (j; 0..26)
		{
			ans[i][j] += cnt[j];
		}
		++cnt[i];
	}

	long ans0 = cnt[cnt.MIN_POS!"a > b"];
	foreach (i; 0..26)
	{
		foreach (j; 0..26)
		{
			ans0.chmax(ans[i][j]);
		}
	}

	writeln(ans0);
	stdout.flush;
	debug readln;
}

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max;

    IO io;
    string s = io.readToken;
    int[] cnt1 = new int[26];
    int[][] cnt2 = new int[][](26, 26);
    for (int i = 0; i < s.length; ++i) {
        int c = s[i] - 'a';
        for (int d = 0; d < 26; ++d) {
            cnt2[d][c] += cnt1[d];
        }
        cnt1[c]++;
    }
    int result = 0;
    for (int c = 0; c < 26; ++c) {
        result = max(result, cnt1[c]);
        for (int d = 0; d < 26; ++d) {
            result = max(result, cnt2[c][d]);
        }
    }
    writeln(result);
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto s = RD!string;
	auto cnt = new long[](26);
	foreach (c; s)
	{
		++cnt[c-'a'];
	}
	cnt.sort!"a > b"();

	long ans = 1;
	ans.chmax(cnt[0]);
	ans.chmax(cnt[0] * cnt[1]);
	ans.chmax(cnt[0]*(cnt[0]-1)/2);

	writeln(ans);
	stdout.flush;
	debug readln;
}


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int t = read.to!int;
	foreach(_; 0 .. t){

		string s = readln.chomp;
		int[char] cnt;
		foreach(c; s){
			if(c !in cnt) cnt[c] = 0;
			cnt[c] += 1;
		}

		string ans;
		char[] ks;
		foreach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;
		log("cnt:", cnt);
		log("ks:", ks);

		void f(char c){
			log("c:", c);
			foreach(j; 0 .. cnt[c]) ans ~= c;
		}

		if(ks.length >= 4){
			for(int i = 1; i < ks.length; i += 2) f(ks[i]);
			for(int i = 0; i < ks.length; i += 2) f(ks[i]);
		}
		else if(ks.length == 3){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]), f(ks[2]);
			}
			else if(ks[2] - ks[1] > 1){
				f(ks[1]), f(ks[2]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 2){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 1){
			f(ks[0]);
		}

		ans.writeln;
	}

}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int t;
    readf("%s", &t);
    readln;

    while (t--) {
        auto s = readln.chomp;

        int[char] cnt;
        foreach (e; s) { ++cnt[e]; }

        debug { cnt.writeln; }

        auto diff = cnt.keys.length.to!int;
        auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;
        if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])
                || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {
            writeln("No answer");
            continue;
        }

        int[] ord;
        if (diff == 3) {
            if (sortedKeys[0] + 1 != sortedKeys[1]) { ord = [1, 0, 2]; }
            else { ord = [1, 2, 0]; }
        } else if (diff == 4) {
            ord = [2, 0, 3, 1];
        } else {
            auto ita = diff.iota;
            ord ~= ita.stride(2).array;
            ord ~= ita.dropOne.stride(2).array;
        }

        debug { ord.writeln; }

        dchar[] ans;
        foreach (e; ord) {
            auto c = sortedKeys[e];
            ans ~= c.repeat(cnt[c.to!char]).array;
        }

        ans.writeln;
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int tests;
	readf (" %s", &tests);
	readln;
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		sort (s.representation);
		auto chars = group (s).array;
		char [] res1;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.drop (k).stride (2))
			{
				res1 ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		char [] res2;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.retro.drop (k).stride (2))
			{
				res2 ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		if (res1.findAdjacent
		    !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)
		{
			writeln (res1);
		}
		else if (res2.findAdjacent
		    !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)
		{
			writeln (res2);
		}
		else
		{
			writeln ("No answer");
		}
	}
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;

void test () {
  auto s = readln.strip;
  int[26] c;
  foreach (i; s) {
    ++c[i.to!int - 97];
  }
  auto x = iota (0, 26, 2), y = iota (1, 26, 2);
  auto r1 = x.filter!(a => c[a] > 0);
  auto r2 = y.filter!(a => c[a] > 0);
  void p (int k) {
    write (replicate ([(97+ k).to!char], c[k]));
  }
  void o(T) (T r) {
    foreach (k; r) {
      p (k);
    }
    writeln;
  }
  if (r1.empty) {
    o (r2);
    return;
  }
  if (r2.empty) {
    o (r1);
    return;
  }
  foreach (i; r1) {
    foreach (j; r2) {
      if (abs (i - j) > 1) {
        foreach (k; r1) {
          if (k != i) p (k);
        }
        p (i);
        p (j);
        foreach (k; r2) {
          if (k != j) p (k);
        }
        writeln;
        return;
      }
    }
  }
  writeln ("No answer");
}

void main() {
  immutable nt = readln.strip.to!int;
  foreach (tid; 0 .. nt) {
    test ();
  }
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement, filter, any;
import std.conv : to;
import std.range : iota, tee, zip;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import std.math : abs;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        string s = readln().strip;
        auto s1 = s.filter!(c => (c - 'a') % 2 == 0).array();
        auto s2 = s.filter!(c => (c - 'a') % 2 == 1).array();
        sort(s1);
        sort(s2);

        if (s1.length > 0 && s2.length > 0) {
            if (abs(to!int(s1[0]) - to!int(s2[$ - 1])) != 1)
                writeln(s2 ~ s1);
            else if (abs(to!int(s2[0]) - to!int(s1[$ - 1])) != 1)
                writeln(s1 ~ s2);
            else
                writeln("No answer");
        }
        else
            writeln(s1 ~ s2);
    }

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement, filter, any;
import std.conv : to;
import std.range : iota, tee, zip;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import std.math : abs;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        auto count = new int[100];
        string s = readln().strip;
        auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;
        auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;
        sort(s1);
        sort(s2);

        auto c1 = s1 ~ s2;
        auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);
        if (!r1) {
            writeln(c1);
            continue;
        }

        auto c2 = s2 ~ s1;
        auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);
        if (!r2) {
            writeln(c2);
            continue;
        }

        writeln("No answer");
    }

}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int t;
    readf("%s", &t);
    readln;

    while (t--) {
        auto s = readln.chomp;

        int[char] cnt;
        foreach (e; s) { ++cnt[e]; }

        debug { cnt.writeln; }

        auto diff = cnt.keys.length.to!int;
        auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;
        if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])
                || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {
            writeln("No answer");
            continue;
        }

        int[] ord;
        if (diff == 4) {
            ord = [2, 0, 3, 1];
        } else {
            auto ita = diff.iota;
            ord ~= ita.stride(2).array;
            ord ~= ita.dropOne.stride(2).array;
        }

        debug { ord.writeln; }

        dchar[] ans;
        foreach (e; ord) {
            auto c = sortedKeys[e];
            ans ~= c.repeat(cnt[c.to!char]).array;
        }

        ans.writeln;
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int tests;
	readf (" %s", &tests);
	readln;
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		sort (s.representation);
		auto chars = group (s);
		char [] res;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.drop (k).stride (2))
			{
				res ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		if (!res.findAdjacent !(q{abs (a - b) == 1}).empty)
		{
			writeln ("No answer");
		}
		else
		{
			writeln (res);
		}
	}
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int t = read.to!int;
	foreach(_; 0 .. t){

		string s = readln.chomp;
		int[char] cnt;
		foreach(c; s){
			if(c !in cnt) cnt[c] = 0;
			cnt[c] += 1;
		}

		string ans;
		char[] ks;
		foreach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;
		log("cnt:", cnt);
		log("ks:", ks);

		void f(char c){
			log("c:", c);
			foreach(j; 0 .. cnt[c]) ans ~= c;
		}

		if(ks.length >= 4){
			for(int i = 1; i < ks.length; i += 2) f(ks[i]);
			for(int i = ((ks.length - 1)/ 2) * 2; i >= 0; i -= 2) log(i), f(ks[i]);
		}
		else if(ks.length == 3){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]), f(ks[2]);
			}
			else if(ks[2] - ks[1] > 1){
				f(ks[1]), f(ks[2]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 2){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 1){
			f(ks[0]);
		}

		ans.writeln;
	}

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import std.math : abs;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main()
{
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T)
    {
        auto count = new int[100];
        char[] s = readln().strip.dup;

        foreach (e; s)
        {
            count[e - 'a']++;
        }

        char[] ans;

        foreach_reverse (c; 0 .. 30)
        {
            if (c % 2 == 0)
            {
                foreach (ii; 0 .. count[c])
                    ans ~= 'a' + c;
            }
        }

        foreach_reverse (c; 0 .. 30)
        {
            if (c % 2 == 1)
            {
                foreach (ii; 0 .. count[c])
                    ans ~= 'a' + c;
            }
        }

        bool flag = false;
        foreach (i, c; ans)
        {
            if (i < to!int(ans.length) - 1 && abs(ans[i] - ans[i + 1]) == 1)
            {
                flag = true;
                break;
            }
        }

        if (flag)
            writeln("No answer");
        else
            writeln(ans);

    }

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement, filter, any;
import std.conv : to;
import std.range : iota, tee, zip;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import std.math : abs;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        auto count = new int[100];
        string s = readln().strip;
        auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;
        auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;
        sort(s1);
        sort(s2);

        auto c1 = s1 ~ s2;
        auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);
        if (!r1) {
            writeln(c1);
            continue;
        }

        auto c2 = s2 ~ s1;
        auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);
        if (!r2) {
            writeln(c2);
            continue;
        }

        writeln("No answer");
    }

}