#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  int b[N + 1];
  int s, c;
  int flag = 0;
  for (int i = 0; i <= N; i++) {
    b[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> s;
    cin >> c;
    if (s == 1) {
      if (c == 0) {
        flag = 1;
      }
    }
    if (b[s] != 0) {
      flag == 1;
    }
    b[s] = c;
  }
  int num = 0;
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    if (b[1] == 0) {
      num = 100 + b[2] * 10 + b[3];
    } else {
      num = b[1] * 100 + b[2] * 10 + b[3];
    }
    cout << num << endl;
  }
}
