#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool check = true;
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < m; k++) {
      if (k == j) continue;
      if (s[j] == s[k] && c[j] != c[k]) check = false;
    }
  }
  if (!check)
    cout << -1 << endl;
  else {
    int a[3] = {};
    for (int i = 0; i < n; i++) {
      int b = 0;
      for (int j = 0; j < m; j++) {
        if (i + 1 == s[j]) b = c[j];
      }
      a[i] = b;
    }
    for (int i = 0; i < n; i++) {
      if (!(i == 0 && a[i] == 0)) cout << a[i];
    }
  }
}
