#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   pair<long long, long long> d[1000009];   long long f[1000009];   deque<pair<long long, long long> > dq;   long long dsum = 0;   int main() {     long long l, m;     scanf( %I64d %I64d , &l, &m);     int(n);     scanf( %d , &n);     d[0].first = 0;     d[0].second = 999999999;     for (int i = (1); i < (n + 1); ++i) {       scanf( %I64d %I64d , &d[i].first, &d[i].second);     }     sort(d, d + n + 1);     d[n + 1].first = l;     d[n + 1].second = 0;     n += 2;     long long ans = 0;     f[0] = m;     for (int i = (1); i < (n); ++i) {       f[i] = f[i - 1] - (d[i].first - d[i - 1].first);       while (f[i] < 0) {         if (((int)(dq).size()) == 0) {           ans = -1;           break;         }         long long buy = min(-f[i], dq[0].second);         dq[0].second -= buy;         ans += buy * dq[0].first;         dsum -= buy;         f[i] += buy;         if (dq[0].second == 0) dq.pop_front();       }       while (((int)(dq).size())) {         if (dq.back().first > d[i].second) {           dsum -= dq.back().second;           dq.pop_back();         } else           break;       }       if ((m - f[i] - dsum) > 0) {         dq.push_back(make_pair(d[i].second, m - f[i] - dsum));         dsum += m - f[i] - dsum;       }       if (ans == -1) break;     }     printf( %I64d , ans);   }   