#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
const int N = 200005;
long long a[N], b[N], sum;
int n, k;
int main() {
  n = read(), k = read();
  for (register int i = 1; i <= k; i++)
    a[i] = read(), b[i] = read(), sum += b[i];
  if (sum > n) puts("-1"), exit(0);
  if (sum < n) puts("1"), exit(0);
  long long res = 0;
  for (register int i = 1; i <= k; i++) res = (res + a[i] * b[i]) % n;
  res = (res - 1ll * n * (n + 1) / 2) % n;
  if (res == 0)
    puts("1");
  else
    puts("-1");
  return 0;
}
