#include <bits/stdc++.h>
using namespace std;
int main() {
  int j, i, n, m, f = 0, w = 0;
  int a[100], s[100];
  cin >> m >> n;
  for (i = 1; i <= n; i++) cin >> s[i] >> a[i];
  for (i = 1; i <= n; i++) {
    if ((s[i] == 1 && a[i] == 0)) {
      cout << "-1";
      w = 1;
      break;
    }
  }
  if (w == 0) {
    for (i = 1; i <= n; i++) {
      for (j = i; j <= n; j++)
        if (s[i] == s[j]) {
          if (a[i] != a[j]) {
            cout << "-1";
            f = 1;
            break;
          }
        }
      if (f == 0) {
        if (n == 1) {
          if (s[i] == 1) printf("%d", a[i]);
          break;
        } else if (n == 2) {
          if (s[i] == 1) printf("%d", a[i]);
          if (s[i] == 2)
            printf("%d", a[i]);
          else
            printf("0");
          break;
        } else if (n == 3) {
          if (s[i] == 1) printf("%d", a[i]);
          if (s[i] == 2)
            printf("%d", a[i]);
          else
            printf("0");
          if (s[i] == 3)
            printf("%d", a[i]);
          else
            printf("0");
          break;
        }
      } else
        break;
    }
  }
  return 0;
}
