#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, s, c;
  cin >> n >> m;
  std::deque<int> deq(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (deq[s - 1] != c) {
      deq[s - 1] = c;
    }
  }
  if (deq.size() != n || deq[0] == 0) {
    if (n != 1 && deq[0] == 0) {
      cout << -1 << endl;
    } else {
      for (int piyo = 0; piyo < deq.size(); piyo++) {
        cout << deq[piyo];
      }
      cout << endl;
    }
  } else {
    for (int hoge = 0; hoge < deq.size(); hoge++) {
      cout << deq[hoge];
    }
  }
  cout << endl;
}
