import java.io.*;
import java.util.*;

public class scanner_av {

	class Permutations {
		public List<int[]> perms;

		private int[] p;
		private boolean[] used;
		private int n;

		public Permutations(int n) {
			this.n = n;
			this.p = new int[n];
			this.used = new boolean[n];
			this.perms = new ArrayList<>();
		}

		public void generate() {
			gen(0);
		}

		private void gen(int pos) {
			if (pos == n) {
				perms.add(p.clone());
				return;
			}
			for (int i = 0; i < n; i++) {
				if (!used[i]) {
					p[pos] = i;
					used[i] = true;
					gen(pos + 1);
					used[i] = false;
				}
			}
		}
	}

	public void solve() {
		int n = in.nextInt(), k = in.nextInt();
		int[] needInversions = new int[n - k + 1];
		for (int i = 0; i < needInversions.length; i++) {
			needInversions[i] = in.nextInt();
		}

		Permutations permGen = new Permutations(k);
		permGen.generate();

		List<int[]> perms = permGen.perms;
		int[] inversions = new int[perms.size()];

		for (int i = 0; i < inversions.length; i++) {
			inversions[i] = calcInversions(perms.get(i));
		}
		
		boolean[][] canCombine = new boolean[perms.size()][perms.size()];
		for (int i = 0; i < perms.size(); i++) {
			for (int j = 0; j < perms.size(); j++) {
				canCombine[i][j] = canCombine(perms.get(i), perms.get(j));
			}
		}
		
		int[][] nextPermutation = new int[perms.size()][k * (k - 1) / 2 + 1];
		for (int i = 0; i < perms.size(); i++) {
			Arrays.fill(nextPermutation[i], -1);
			for (int j = 0; j < perms.size(); j++) {
				if (canCombine[i][j]) {
					nextPermutation[i][inversions[j]] = j;
				}
			}
		}
		
		int[] restored = new int[n - k + 1];
		outerLoop: for (int firstPerm = 0; firstPerm < perms.size(); firstPerm++) {
			int curPerm = firstPerm;
			if (inversions[curPerm] != needInversions[0]) {
				continue;
			}
			restored[0] = curPerm;
			for (int i = 1; i < n - k + 1; i++) {
				int needInv = needInversions[i];
				if (nextPermutation[curPerm][needInv] == -1) {
					continue outerLoop;
				}
				curPerm = nextPermutation[curPerm][needInv];
				restored[i] = curPerm;
			}
			
			restorePermutation(restored, n, k, perms);
			return;
		}
		
		throw new AssertionError();
	}
	
	List<Integer>[] graph;
	List<Integer> topSort;
	boolean[] vis;
	
	private void restorePermutation(int[] restored, int n, int k, List<int[]> perms) {
		graph = new List[n];
		topSort = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<>();
		}
		vis = new boolean[n];
		
		for (int i = 0; i < n - k + 1; i++) {
			int[] perm = perms.get(restored[i]);
			
			for (int x = 0; x < k; x++) {
				for (int y = 0; y < k; y++) {
					if (perm[x] < perm[y]) {
						graph[i + x].add(i + y);
					} else {
						graph[i + y].add(i + x);
					}
				}
			}
		}
		
		for (int i = 0; i < n; i++) {
			if (!vis[i]) {
				dfs(i);
			}
		}
		
		Collections.reverse(topSort);
		
		int[] result = new int[n];
		for (int i = 0; i < n; i++ ){
			result[topSort.get(i)] = i;
		}
		for (int i = 0; i < n; i++) {
			out.print((result[i] + 1) + " ");
		}
	}
	
	void dfs(int u) {
		vis[u] = true;
		for (int v : graph[u]) {
			if (!vis[v]) {
				dfs(v);
			}
		}
		topSort.add(u);
	}

	private boolean canCombine(int[] a, int[] b) {
		int[] checkA = Arrays.copyOfRange(a, 1, a.length);
		int[] checkB = Arrays.copyOfRange(b, 0, b.length - 1);
		return areEquivalent(checkA, checkB);
	}

	private boolean areEquivalent(int[] checkA, int[] checkB) {
		int lastA = Integer.MIN_VALUE, lastB = Integer.MIN_VALUE;
		for (int i = 0; i < checkA.length; i++) {
			int minA = -1, minB = -1;
			for (int j = 0; j < checkA.length; j++) {
				if (checkA[j] > lastA && (minA == -1 || checkA[j] < checkA[minA])) {
					minA = j;
				}
				if (checkB[j] > lastB && (minB == -1 || checkB[j] < checkB[minB])) {
					minB = j;
				}
			}
			if (minA != minB) {
				return false;
			}
			lastA = checkA[minA];
			lastB = checkB[minB];
		}
		return true;
	}

	int calcInversions(int[] a) {
		int result = 0;
		for (int i = 0; i < a.length; i++) {
			for (int j = i + 1; j < a.length; j++) {
				result += a[i] > a[j] ? 1 : 0;
			}
		}
		return result;
	}

	FastScanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new FastScanner("scanner.in");
			out = new PrintWriter("scanner.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String name) {
			try {
				br = new BufferedReader(new FileReader(name));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new scanner_av().run();
	}
}
