#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(3);
  bool det = true;
  for (int i = 0; i < 3; i++) ans.at(i) = -1;
  for (int i = 0; i < m; i++) {
    int buf_s, buf_c;
    cin >> buf_s >> buf_c;
    buf_s--;
    if (ans.at(buf_s) == -1) {
      ans.at(buf_s) = buf_c;
    } else {
      if (ans.at(buf_s) != buf_c) det = false;
    }
  }
  if (n == 3 && ans.at(0) == 0) det = false;
  if (det) {
    if (ans.at(0) == -1) ans.at(0) = 1;
    if (ans.at(1) == -1) ans.at(1) = 0;
    if (ans.at(2) == -1) ans.at(2) = 0;
    for (int i = 0; i < n; i++) {
      cout << ans.at(i);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
