#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
template <class T>
void read(T &x) {
  int f = 0;
  x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
const int N = 200005;
int a[N], b[N], p[N], n, K;
long long sum, aim, now;
int main() {
  read(n), read(K);
  for (int i = (1); i <= (K); i++) {
    read(a[i]), read(b[i]);
    p[i] = i;
    sum += b[i];
  }
  if (sum > n) {
    puts("-1");
    return 0;
  }
  if (sum < n) {
    puts("1");
    return 0;
  }
  aim = (long long)n * (n - 1) / 2 % n;
  long long acc = 0;
  sort(p + 1, p + K + 1, [&](int x, int y) { return a[x] < a[y]; });
  p[K + 1] = K + 1;
  a[K + 1] = n + 1;
  for (int i = (1); i <= (K); i++) {
    acc = (acc + b[p[i]]) % n;
    now = (now + acc * (a[p[i + 1]] - a[p[i]])) % n;
  }
  if (now != aim) {
    puts("-1");
  } else {
    puts("1");
  }
  return 0;
}
