#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int a[5];
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    a[i] = 0;
    if (s[i] == 1 && c[i] == 0) ok = true;
  }
  for (int i = 0; i < m - 1; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) ok = true;
    }
  }
  if (ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    a[s[i] - 1] = c[i];
  }
  for (int i = 0; i < 3; i++) {
    if (!a[i] && i == 0) cout << 1;
    if (!a[i])
      cout << 0;
    else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
