#include <bits/stdc++.h>
using namespace std;
const int M = 5;
int main() {
  int n, m;
  int num[4] = {};
  cin >> n >> m;
  bool flag = false;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (num[4 - n + s] < c) {
      num[4 - n + s] = c;
      if (s == 1 && (c != 0 || n == 1)) {
        flag = true;
      } else {
        flag = false;
      }
    }
  }
  if (!flag) {
    cout << -1 << endl;
  } else {
    cout << num[1] * 100 + num[2] * 10 + num[3] << endl;
  }
  return 0;
}
