#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) cin >> s.at(i) >> c.at(i);
  if (n == 1) {
    for (int i = 0; i < (m - 1); ++i) {
      for (int j = i + 1; j < m; j++) {
        if (c[i] != c[j]) {
          cout << "-1" << endl;
          return 0;
        }
      }
      if (i == m - 2) {
        cout << c[0] << endl;
      }
    }
  }
  if (n == 2) {
    for (int i = 10; i < 100; i++) {
      string q = to_string(i);
      for (int j = 0; j < (m); ++j) {
        if (q[s[j] - 1] != c[j]) break;
        if (j == m - 1) {
          cout << "q" << endl;
          return 0;
        }
      }
    }
    cout << -1 << endl;
  }
  if (n == 3) {
    for (int i = 100; i < 1000; i++) {
      string q = to_string(i);
      for (int j = 0; j < (m); ++j) {
        if (q[s[j] - 1] != c[j]) break;
        if (j == m - 1) {
          cout << "q" << endl;
          return 0;
        }
      }
    }
    cout << -1 << endl;
  }
  return 0;
}
