#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<priority_queue<int, vector<int>, greater<int>>> pq(N);
  vector<int> s(M, 0), c(M, 0);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < M; i++) {
    pq[s[i] - 1].push(c[i]);
  }
  for (int i = 0; i < N; i++) {
    if (pq[i].empty()) {
      if (i == 0) {
        cout << -1;
        exit(0);
      }
      cout << 0;
      continue;
    }
    if (pq[0].top() == 0) {
      cout << -1;
      exit(0);
    }
    cout << pq[i].top();
    pq[i].pop();
  }
  return 0;
}
