#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s = "";
  for (int i = 0; i < n; i++) {
    s += '0';
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    char c;
    cin >> a >> b;
    if (b == 0) c = '0';
    if (b == 1) c = '1';
    if (b == 2) c = '2';
    if (b == 3) c = '3';
    if (b == 4) c = '4';
    if (b == 5) c = '5';
    if (b == 6) c = '6';
    if (b == 7) c = '7';
    if (b == 8) c = '8';
    if (b == 9) c = '9';
    a--;
    b = (int)s[a];
    if (b == 0) c = '0';
    if (b == 1) c = '1';
    if (b == 2) c = '2';
    if (b == 3) c = '3';
    if (b == 4) c = '4';
    if (b == 5) c = '5';
    if (b == 6) c = '6';
    if (b == 7) c = '7';
    if (b == 8) c = '8';
    if (b == 9) c = '9';
    int val = b;
    int chk = (int)c;
    if (val >= chk && chk != 48 || s[a] == '0' && chk != 48) s[a] = c;
  }
  if (s[0] == '0' && n != 1)
    cout << -1;
  else
    cout << s;
  return 0;
}
