#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, x, y, a = 1;
  cin >> n >> m;
  char c;
  string s = "";
  for (i = 0; i < n; i++) {
    s += "-";
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    c = '0' + y;
    if (s[x - 1] == '-' || s[x - 1] > c) {
      s[x - 1] = c;
    }
  }
  for (i = 0; i < n; i++)
    if (s[i] == '-') s[i] = '0';
  if (s[0] == '0') {
    cout << -1 << endl;
  } else {
    cout << s << endl;
  }
}
