#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string str = "";
  for (int i = 0; i < n; i++) {
    str += "-";
  }
  for (int i = 0; i < k; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (str[s - 1] == '-' || str[s - 1] > c) {
      if (c == '0' && s - 1 == 0 && str.size() != 1) {
        continue;
      }
      str[s - 1] = c;
    }
  }
  for (int i = 0; i < n; i++) {
    if (str[i] == '-') {
      str[i] = '0';
    }
  }
  if (str[0] != '0' || str.size() == 1) {
    cout << str;
  } else {
    cout << -1;
  }
}
