int x = 0;
Scanner sc = new Scanner(System.in);
if (sc.hasNext()) {
x = sc.nextInt();
}
int n =0;
if(sc.hasNext()) {
n = sc.nextInt();
}
String[] a = new String[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
sc.nextLine();
a[i] = sc.next();
b[i] = sc.nextInt();
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (b[j + 1] > b[j]) {
int temp = b[j];
b[j] = b[j + 1];
b[j] = temp;
} else if (b[j + 1] == b[j]) {
if (a[j].compareTo(a[j + 1]) > 0) {
String t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
for (int i = 0; i < n; i++) {
if (b[i] >= x) {
System.out.println(a[i] + " " + b[i]);
}
}