第二题 m, n = map(int,input().split()) stations = [] prices = [] for _ in range(n): s,p = map(int,input().split()) stations.append(s) prices.append(p) mono_stack=[] ret=[-1]*n for i in range(n): while mono_stack and prices[i] <= prices[mono_stack[-1]]: ret[mono_stack.pop()] = i mono_stack.append(i) i=0 ans = 0 amounts=[0]*n while ret[i]!=-1: amounts[i] = stations[ret[i]]-stations[i] ans += amounts[i]*prices[i] i = ret[i] amounts[i] = m-stations[i] ans += amounts[i]*prices[i] print(ans)