#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, i = 0, j, s[100010], c[100010], ans[100010];
  for (i = 0; i < 9; i++) {
    ans[i] = 10;
  }
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (c[i] == ans[s[i]] - 10) {
      continue;
    }
    ans[s[i]] += c[i];
    if (c[i] != ans[s[i]] - 10) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (i = 1; i <= n; i++)
    if (i == 1 && ans[i] == 10) {
      cout << "-1" << endl;
      return 0;
    }
  cout << ans[i] - 10;
  return 0;
}
