#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int A[3];
bool B[3];
int main() {
  int N, M;
  cin >> N >> M;
  bool flag = true;
  for (int i = 0; i < (int)(M); i++) {
    int s, c, idx;
    cin >> s >> c;
    s--;
    if (!B[s]) {
      A[s] = c;
      B[s] = true;
    }
    if (B[s] && A[s] != c) {
      flag = false;
      break;
    }
  }
  bool ok = true;
  if (N == 1) {
    if (A[0] == 0 && A[1] == 0 && A[2] == 0) ok = false;
  } else {
    if (B[0] && A[0] == 0) {
      ok = false;
    } else {
      if (B[1] && A[1] == 0) {
        B[0] = true;
        A[0] = 1;
      }
    }
  }
  if (flag && ok) {
    for (int i = 0; i < (int)(3); i++) cout << A[i];
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
