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