#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;
    idx = s - 1;
    if (!B[idx]) {
      A[idx] = c;
      B[idx] = true;
    }
    if (B[idx] && A[idx] != c) {
      flag = false;
      break;
    }
  }
  if (flag && A[0] != 0) {
    for (int i = 0; i < (int)(3); i++) cout << A[i];
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
