#include <bits/stdc++.h>
using namespace std;
int nC2(int n);
int main() {
  int N, M;
  cin >> N >> M;
  string ret;
  for (int i = 0; i < N; i++) {
    ret.push_back('x');
  }
  int s, c;
  char n;
  int err = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    n = '0' + c;
    s--;
    if (ret[s] == 'x' || ret[s] == n) {
      ret[s] = n;
    } else {
      err = 1;
      break;
    }
  }
  if (N != 1 && ret[0] == '0') err = 1;
  if (N != 1 && ret[0] == 'x') ret[0] = 1;
  if (err) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < N; i++) {
    if (ret[i] == 'x') {
      ret[i] = '0';
    }
  }
  cout << ret << endl;
  return 0;
}
int nC2(int n) {
  if (n <= 1)
    return 0;
  else
    return n * (n - 1) / 2;
}
