@staticmethod
def d():
    (w, n, k, *ab) = map(int, sys.stdin.read().split())
    dp = np.zeros(((k + 1), (w + 1)), dtype=np.int32)
    for (a, b) in zip(*([iter(ab)] * 2)):
        prev = dp.copy()
        np.maximum(dp[1:, a:], (prev[:(- 1), :(- a)] + b), out=dp[1:, a:])
    print(dp[k][w])
@staticmethod
def d():
    (w, n, k, *ab) = map(int, sys.stdin.read().split())
    dp = np.zeros(((k + 1), (w + 1)), dtype=np.int32)
    for (a, b) in zip(*([iter(ab)] * 2)):
        prev = dp.copy()
        np.maximum(dp[1:, a:], (prev[:(- 1), :(- a)] + b), out=dp[1:, a:])
    print(dp[k][w])