#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  map<int, int> ans;
  for (int i = 0; i < M; i++) {
    if (ans.count(s.at(i))) {
      if (c.at(i) < ans.at(s.at(i))) {
        ans[s.at(i)] = c.at(i);
      }
    }
    ans[s.at(i)] = c.at(i);
  }
  if (N == 1) {
    if (ans.count(1) != false) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (ans.count(i) == false) {
      ans[i] = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (N != 1) {
      if (ans.at(1) == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << ans.at(i);
  }
  return 0;
}
