#include <bits/stdc++.h>
using namespace std;
int MAX_N = 100;
int main() {
  int N, M;
  int n[3] = {-1, -1, -1};
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (n[s - 1] == -1 || n[s - 1] == c) {
      n[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n[0] == -1) n[0] = 1;
  if (n[1] == -1) n[1] = 0;
  if (n[2] == -1) n[2] = 0;
  cout << n[0] << n[1] << n[2] << endl;
  return 0;
}
