#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[0] != 0) {
    for (int hoge = 0; hoge < deq.size(); hoge++) {
      cout << deq[hoge];
    }
    cout << endl;
  } else if (n == 1) {
    cout << 0 << endl;
  } else {
    cout << -1 << endl;
  }
}
