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