#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, s[5], c[5];
  char a[3];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    a[i] = '0';
  }
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] <= N && (a[s[i] - 1] == '0' || a[s[i] - 1] == '0' + c[i])) {
      a[s[i] - 1] = '0' + c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
    if ((s[i] == 1 && c[i] == 0) && N > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  int flag = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] != '0' || flag > 0) {
      cout << a[i];
      flag++;
    }
  }
  cout << endl;
  return 0;
}
