#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[6], c[6];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int j = 0; j < 1000; j++) {
    string js;
    js = j;
    bool res = true;
    for (int k = 0; k < M; k++) {
      if (js[s[k] - 1] != (char)c[k]) res = false;
    }
    if (res) {
      cout << j << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
