#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  bool b[4] = {};
  cin >> N >> M;
  map<int, int> m;
  for (int i = 1; i <= 3; i++) {
    m[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (!b[s]) {
      b[s] = true;
      m[s] = c;
    } else {
      if (m[s] == 0) m[s] = c;
      if (c < m[s] && c >= 0 && s != 1) m[s] = c;
      if (c < m[s] && c > 0 && s == 1) m[s] = c;
    }
  }
  if (m[1] == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    cout << m[i];
  }
  cout << endl;
}
