#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  bool a = false;
  vector<char> num(N + 1, ' ');
  num.at(0) = '0' + 1;
  for (int i = 0; i < M; i++) {
    if (num.at(s.at(i)) == ' ') {
      num.at(s.at(i)) = '0' + c.at(i);
      a = true;
    } else if (num.at(s.at(i)) == '0' + c.at(i)) {
      a = true;
    } else {
      a = false;
      break;
    }
  }
  for (int i = 1; i < N + 1; i++) {
    if (num.at(i) == ' ') {
      num.at(i) = '0';
    }
  }
  int cnt = 0;
  for (int i = 1; i < N + 1; i++) {
    if (num.at(i) == '0') {
      cnt++;
    }
  }
  if (cnt == N) {
    a = false;
  }
  if (a) {
    for (int i = 1; i < N + 1; i++) {
      cout << num.at(i);
      if (i == N) {
        cout << endl;
      }
    }
  } else {
    cout << -1 << endl;
  }
}
