#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m, s, c, keta = 0;
  int s1, s2, s3;
  s1 = s2 = s3 = -1;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (s == 1 && (s1 == -1 || s1 == c)) {
      s1 = c;
    } else if (s == 2 && (s2 == -1 || s2 == c)) {
      s2 = c;
    } else if (s == 3 && (s3 == -1 || s3 == c)) {
      s3 = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  if (n == 3) {
    if (s1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s1 == -1 && s2 == -1) {
      ans = 100 + s3;
    } else if (s1 == -1 && s3 == -1) {
      ans = 100 + s2 * 10;
    } else if (s2 == -1 && s3 == -1) {
      ans = s1 * 100;
    } else if (s1 == -1) {
      ans = 100 + s2 * 10 + s3;
    } else if (s2 == -1) {
      ans = s1 * 100 + s3;
    } else if (s3 == -1) {
      ans = s1 * 100 + s2 * 10;
    } else {
      ans = s1 * 100 + s2 * 10 + s3;
    }
  } else if (n == 2) {
    if (s1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s1 == -1)
      ans = 10 + s2;
    else if (s2 == -1)
      ans = 10 * s1;
    else
      ans = s1 * 10 + s2;
  } else if (n == 1) {
    ans = s1;
  }
  cout << ans << endl;
  return 0;
}
