import java.util.*;
public class Main {
static final int N = 1002, M = 502, K = 102;
static int[][][] f = new int[K][N][M];
static int[] v1 = new int[K], v2 = new int[K];
static int n, m, k;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().split(" ");
n = Integer.parseInt(str[0]);
m = Integer.parseInt(str[1]);
k = Integer.parseInt(str[2]);
for (int i = 1; i <= k; i++) {
str = sc.nextLine().split(" ");
v1[i] = Integer.parseInt(str[0]);
v2[i] = Integer.parseInt(str[1]);
}
for (int i = 1; i <= k; i++)
for (int j = 1; j <= n; j++)
for (int t = 1; t <= m; t++) {
f[i][j][t] = f[i - 1][j][t];
if (v1[i] <= j && v2[i] < t)//没等号的解法
f[i][j][t] = Math.max(f[i][j][t], f[i - 1][j - v1[i]][t - v2[i]] + 1);
}
int ans1 = f[k][n][m], i = 1;
if (ans1 != 0) {
for (i = 1; i <= m; i++)
if (ans1 == f[k][n][i + 1]) break;//找到第一个就是最小值
} else i = 0;//为零的时候直接取i为零
System.out.println(ans1 + " " + (m - i));
}
}