// Arup Guha
// 2/1/2015
// Solution to 2014 MCPC Problem E: Word Cloud

import java.util.*;

public class e {

	final public static int SPACE = 10;

	public static void main(String[] args) {

		// Start reading first case.
		Scanner stdin = new Scanner(System.in);
		int width = stdin.nextInt();
		int n = stdin.nextInt();
		int loop = 1;

		// Go through all cases.
		while (width != 0) {

			int max = 0;
			ArrayList<word> list = new ArrayList<word>();

			// Read in items screening out those with frequencies less than 5.
			for (int i=0; i<n; i++) {
				String item = stdin.next();
				int freq = stdin.nextInt();
				max = Math.max(max, freq);
				if (freq >= 5) list.add(new word(item, freq));
			}

			int height = 0, curIndex = 0, curWidth = 0, curHeight = 0;

			// Go through whole list.
			while (curIndex < list.size()) {

				boolean start = true;
				int maxRowHeight = 0;

				// Go through this line.
				while (curWidth < width && curIndex < list.size()) {

					// Figure out spec for this word.
					int pts = 8 + (int)(Math.ceil(40.0*(list.get(curIndex).freq-4)/(max-4)));
					int wordWidth = (int)(Math.ceil(9.0/16*list.get(curIndex).str.length()*pts));
					if (!start) wordWidth += SPACE;

					// Oops doesn't fit!
					if (curWidth + wordWidth > width) break;

					// Update parameters for this row.
					curWidth += wordWidth;
					maxRowHeight = Math.max(pts, maxRowHeight);
					curIndex++;
					start = false;
				}

				// Advance to next row.
				height += maxRowHeight;
				curWidth = 0;
			}

			// Output result.
			System.out.println("CLOUD "+loop+": "+height);

			// Get next case.
			width = stdin.nextInt();
			n = stdin.nextInt();
			loop++;
		}
	}
}

class word {

	public String str;
	public int freq;

	public word(String s, int f) {
		str = s;
		freq = f;
	}
}