#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c, ans = 0;
  cin >> n >> m;
  int p[4] = {};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    p[i] = s * 10 + c;
  }
  sort(p, p + m);
  for (int i = 0; i < m - 1; i++) {
    if ((p[i] / 10 == p[i + 1] / 10) && (p[i] % 10 != p[i + 1] % 10)) ans = 1;
  }
  int an = 0;
  if (ans == 1)
    cout << -1 << endl;
  else {
    for (int i = 0; i < m; i++) {
      if (p[i] / 10 == p[i + 1] / 10) continue;
      an += p[i] % 10 * pow(10, n - p[i] / 10);
    }
    cout << an / pow(10, n - 1) << endl;
    cout << an << endl;
    if ((an / pow(10, n - 1) < 1 && an != 0) || (n != 1 && an == 0))
      cout << -1 << endl;
    else
      cout << an << endl;
  }
}
