#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll ndigit(ll n) {
  ll c = 0;
  while (n > 0) {
    n /= 10;
    ++c;
  }
  return c;
}
int main() {
  ll N, M;
  cin >> N >> M;
  ll s, c;
  vec D(M, -1);
  bool f = true;
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    cin >> s >> c;
    --s;
    if (D[s] != c && D[s] != -1)
      f = false;
    else
      D[s] = c;
  }
  cout << (f) << endl;
  ll num;
  if (N == 1) {
    for (ll(i) = (1), i_len = (M); (i) < (i_len); ++(i)) {
      if (D[i] != -1) f = false;
    }
    if (f)
      num = D[0];
    else
      num = -1;
  } else if (N == 2) {
    for (ll(i) = (2), i_len = (M); (i) < (i_len); ++(i)) {
      if (D[i] != -1) f = false;
    }
    if (f) {
      if (D[1] == -1) D[1] = 0;
      num = D[0] * 10 + D[1];
      if (D[0] == 0) num = -1;
    } else
      num = -1;
  } else {
    for (ll(i) = (3), i_len = (M); (i) < (i_len); ++(i)) {
      if (D[i] != -1) f = false;
    }
    if (f) {
      if (D[1] == -1) D[1] = 0;
      if (D[2] == -1) D[2] = 0;
      num = D[0] * 100 + D[1] * 10 + D[2];
      if (D[0] == 0) num = -1;
    } else
      num = -1;
  }
  cout << (num) << endl;
  return 0;
}
