#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, keta[3] = {0}, ans;
  int c[5], s[5];
  bool hantei = true;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    keta[s[i] - 1] = c[i];
    for (int j = 0; j < i; j++) {
      if ((s[j] == s[i]) && (c[j] != c[i])) {
        hantei = false;
      }
    }
    if ((s[i] == 1) && (c[i] == 0)) {
      hantei = false;
    }
  }
  if ((keta[0] == 0) && (hantei)) {
    keta[0] = 1;
  }
  switch (n) {
    case 3:
      ans = keta[0] * 100 + keta[1] * 10 + keta[2];
      break;
    case 2:
      ans = keta[0] * 10 + keta[1];
      break;
    case 1:
      ans = keta[0];
      break;
  }
  if (hantei) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
