#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> C(M);
  for (int i = 0; i < M; i++) {
    cin >> C[i].first >> C[i].second;
    if (C[i].first == 1 && C[i].second == 0) {
      if (N != 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  sort(C.begin(), C.end());
  for (int i = 0; i < M; i++) {
    int j = i;
    while (C[i].first == C[j].first) {
      if (C[i].second != C[j].second) {
        cout << -1 << endl;
        return 0;
      }
      j++;
    }
  }
  string ans;
  for (int i = 0; i < N; i++) {
    ans[i] = '0';
    for (int j = 0; j < M; j++) {
      if (i == C[j].first - 1) {
        if (j == 0 || C[j - 1].first != C[j].first) {
          ans[i] = '0' + C[j].second;
        }
      }
    }
    cout << ans[i];
  }
  return 0;
}
