#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, flag, i;
  flag = 0;
  cin >> n >> m;
  vector<int> num(n + 1, -1);
  vector<int> s(m), c(m);
  for (i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (num.at(s.at(i)) == -1) {
      num.at(s.at(i)) = c.at(i);
    } else {
      if (num.at(s.at(i)) != c.at(i)) {
        flag = 1;
      }
    }
  }
  if (n >= 2 && num.at(1) == 0) {
    flag = 1;
  }
  if (n >= 2 && flag == 0) {
    if (num.at(1) == -1) {
      num.at(1) = 1;
    }
    if (num.at(2) == -1) {
      num.at(2) = 0;
    }
    if (num.at(3) == -1) {
      num.at(3) = 0;
    }
  }
  if (n == 1 && flag == 0) {
    if (num.at(1) == -1) {
      num.at(1) = 0;
    }
  }
  if (flag == 0) {
    if (n == 1) {
      cout << num.at(1) << endl;
    } else if (n == 2) {
      cout << num.at(1) << num.at(2) << endl;
    } else if (n == 3) {
      cout << num.at(1) << num.at(2) << num.at(3) << endl;
    }
  } else if (flag == 1) {
    cout << -1 << endl;
  }
  return 0;
}
