#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[5], c[5], t;
  int a[3] = {0, 0, 0};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if ((i + 1) == s[j]) {
        if (a[i] > 0 && a[i] != c[j]) {
          cout << "-1" << endl;
          t = 99;
          break;
        } else
          a[i] = c[j];
      }
    }
    if (t == 99) break;
    if (a[0] != 0 && n > 1)
      cout << a[i];
    else {
      cout << "-1" << endl;
      break;
    }
  }
}
