#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M + 1);
  vector<int> c(M + 1);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  bool flag = true;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (i == j) continue;
      if (s.at(i) == s.at(j) && c.at(i) == c.at(j)) {
        s.at(j) = 0;
        c.at(j) = 0;
      } else if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        flag = false;
      }
    }
  }
  int k = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 1; j <= 3; j++) {
      if (s.at(i) == j) {
        int x = 3 - j;
        k += pow(10, x) * c.at(i);
      }
    }
  }
  if (flag && k / pow(10, N) != 0 && k / pow(10, N) < 10)
    cout << k << endl;
  else
    cout << -1 << endl;
}
