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