#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a = -1, b = -1, c = -1;
  bool ret = false;
  for (int i = 0; i < m; i++) {
    int aa, bb;
    cin >> aa >> bb;
    if (aa == 1) {
      if (a == -1 || a == bb) {
        a = bb;
      } else {
        ret = true;
      }
    }
    if (aa == 2) {
      if (b == -1 || b == bb) {
        b = bb;
      } else {
        ret = true;
      }
    }
    if (aa == 3) {
      if (c == -1 || c == bb) {
        c = bb;
      } else {
        ret = true;
      }
    }
  }
  int num = -1;
  if (ret == false) {
    if (a == -1 && n == 3) {
      a = 1;
    } else if (a == -1) {
      a = 0;
    }
    if (b == -1 && n == 2) {
      b = 1;
    } else if (b == -1) {
      b = 0;
    }
    if (c == -1) {
      c = 0;
    }
    num = a * 100 + b * 10 + c;
    if (a == 0 && n == 3) {
      num = -1;
    }
    if (a == 0 && b == 0 && n == 2) {
      num = -1;
    }
  }
  cout << num << endl;
}
