#include <bits/stdc++.h>
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
  return x > y ? x : y;
};
const int INF = 2000000005;
const long long mod = 1000000007;
const long long MAXN = 505;
long long N, K;
long long sum, tmp;
int main() {
  long long a, b;
  scanf("%lld %lld", &N, &K);
  for (int i = 1; i <= K; i++) {
    scanf("%lld %lld", &a, &b);
    sum = (sum + a * b % N) % N;
    tmp += b;
  }
  if (tmp < N || tmp == N && sum == (N + 1) * N / 2 % N)
    printf("1\n");
  else
    printf("-1\n");
  return 0;
}
