#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (size_t i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (N != 1 && (s[i] == 1 & c[i] == 0)) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int one = -1;
  int two = -1;
  int three = -1;
  for (size_t i = 0; i < M; i++) {
    if (s[i] == 1) {
      if (one == -1) {
        one = c[i];
      } else {
        if (one != c[i]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    if (s[i] == 2) {
      if (two == -1) {
        two = c[i];
      } else {
        if (two != c[i]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    if (s[i] == 3) {
      if (three == -1) {
        three = c[i];
      } else {
        if (three != c[i]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
  }
  if (one == -1) {
    if (N == 3) {
      one = 1;
    } else {
      one = 0;
    }
  }
  if (two == -1) {
    if (N == 2) {
      two = 1;
    } else {
      two = 0;
    }
  }
  if (three == -1) {
    three = 0;
  }
  int ans = 100 * one + 10 * two + three;
  cout << ans << endl;
}
