#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int s;
  char c;
  int zero = 0, n_zero = 0;
  string str = "000";
  for (int(i) = (0); (i) < (m); (i)++) {
    cin >> s >> c;
    s--;
    if (c != '0')
      n_zero = max(n_zero, s);
    else
      zero = max(zero, s);
    if (str[s] == '0' || str[s] == c) {
      str[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (zero < n_zero) {
    cout << str.substr(3 - n, n) << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
