#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  char num[N];
  int check[N];
  for (int i = 0; i < N; i++) {
    num[i] = '0';
    check[i] = 0;
  }
  bool check2 = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (s[j] - 1 == i) {
        if (check[i] != 0 && c[j] != num[i] - '0') {
          check2 = false;
        }
        num[i] = '0' + c[j];
        check[i] = 1;
      }
    }
  }
  if (num[0] == '0') {
    check2 = false;
  }
  if (!check2) {
    cout << -1 << endl;
  } else {
    cout << num << endl;
  }
}
