#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, string>> v(m);
  for (int i = 0; i < (int)(m); i++) {
    int a;
    string b;
    cin >> a >> b;
    pair<int, string> p = make_pair(a, b);
    v[i] = p;
  }
  int ans = 0;
  bool f = true;
  for (int i = 0; i < 1000; i++) {
    f = true;
    string s;
    s = to_string(i);
    if (s.size() != n)
      continue;
    else {
      for (int j = 0; j < m; j++) {
        pair<int, string> p = v[j];
        if (s[(p.first) - 1] != p.second[0]) {
          f = false;
          break;
        }
      }
    }
    if (f) {
      f = true;
      cout << i << endl;
      ans = i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
