#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[i];
    cin >> c[i];
  }
  int N1 = 0;
  int N2 = 0;
  int N3 = 0;
  int count1 = 0;
  int count2 = 0;
  int count3 = 0;
  int out = -1;
  for (int i = 0; i < M; ++i) {
    if (s[i] == 1) {
      if (c[i] == 0) {
        out = -1;
        break;
      }
      if (count1 != 0) {
        if (N1 != c[i]) {
          out = -1;
          break;
        }
      }
      N1 = c[i];
      out = 1;
      ++count1;
    } else if (s[i] == 2) {
      if (count2 != 0) {
        if (N2 != c[i]) {
          out = -1;
          break;
        }
      }
      N2 = c[i];
      out = 1;
      ++count2;
    } else if (s[i] == 3) {
      if (count3 != 0) {
        if (N3 != c[i]) {
          out = -1;
          break;
        }
      }
      N3 = c[i];
      out = 1;
      ++count3;
    }
  }
  if (out == -1) {
    cout << out;
    return 0;
  }
  out = N1 * 100 + N2 * 10 + N3;
  cout << out;
  return 0;
}
