{"raw_statement":[{"iden":"problem statement","content":"You are given a sequence of positive integers $A=(A_1,A_2,\\ldots,A_N)$ of length $N$, and you will perform $Q$ operations on it. For $1\\leq q\\leq Q$, the $q$\\-th operation is given as positive integers $i_q, x_q$ (where $1\\leq i_q\\leq N$), and it adds $x_q$ to $A_{i_q}$.\nYour goal is to appropriately determine the initial state of $A$ so that the following condition holds at any point in time (that is, in the initial state and immediately after each operation).\n\n*   $0<A_1 < A_2 < \\cdots < A_N$ holds.\n\nWhen achieving this goal, find the minimum possible sum of elements in the initial state of $A$."},{"iden":"constraints","content":"*   $2\\leq N\\leq 2\\times 10^5$\n*   $1\\leq Q\\leq 2\\times 10^5$\n*   $1\\leq i_q\\leq N$\n*   $1\\leq x_q\\leq 10^5$\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $Q$\n$i_1$ $x_1$\n$\\vdots$\n$i_Q$ $x_Q$"},{"iden":"sample input 1","content":"4 2\n1 2\n2 3"},{"iden":"sample output 1","content":"22\n\nSuppose the initial state of $A$ is $A=(1,4,8,9)$. Then,\n\n*   $A$ immediately after the $1$\\-st operation: $A=(3,4,8,9)$\n*   $A$ immediately after the $2$\\-nd operation: $A=(3,7,8,9)$\n\nand it can be verified that $A$ satisfies the condition at any point in time.\nIn this case, the sum of elements in the initial state of $A$ is $\\displaystyle \\sum_{i=1}^NA_i=1+4+8+9=22$."},{"iden":"sample input 2","content":"4 2\n2 3\n1 2"},{"iden":"sample output 2","content":"16"},{"iden":"sample input 3","content":"100000 1\n1 100000"},{"iden":"sample output 3","content":"14999950000"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}