#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m], x[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
    x[i] = 0;
  }
  if (n == m) {
    for (int i = 0; i < m; i++) {
      x[s[i] - 1] = c[i];
    }
    for (int i = 0; i < m; i++) {
      cout << x[i];
      return 0;
    }
  }
  cout << "-1";
}
