#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  queue<int> hundred;
  queue<int> ten;
  queue<int> one;
  bool frag = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (N == 3 && s == 1) {
      if (hundred.empty()) {
        hundred.push(c);
        continue;
      }
      if (hundred.front() != c) {
        frag = false;
      }
    } else if ((N == 3 && s == 2) || (N == 2 && s == 1)) {
      if (ten.empty()) {
        ten.push(c);
        continue;
      }
      if (ten.front() != c) {
        frag = false;
      }
    } else if ((N == 3 && s == 3) || (N == 2 && s == 2) || (N == 1 && s == 1)) {
      if (one.empty()) {
        one.push(c);
        continue;
      }
      if (one.front() != c) {
        frag = false;
      }
    }
  }
  if (hundred.empty()) {
    hundred.push(0);
  }
  if (ten.empty()) {
    ten.push(0);
  }
  if (one.empty()) {
    one.push(0);
  }
  int h = hundred.front();
  int t = ten.front();
  int o = one.front();
  if (N == 1) {
    cout << o << endl;
  } else if (N == 2) {
    if (t != 0) {
      cout << t * 10 + o << endl;
    } else {
      cout << -1 << endl;
    }
  } else if (N == 3) {
    if (h != 0) {
      cout << h * 100 + t * 10 + o << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
