#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  set<int> se;
  vector<int> num(4);
  bool ans = true;
  for (int i = 0; i < (int)(M); i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0 || se.count(a) && num.at(a) != b) {
      ans = false;
    } else {
      se.insert(a);
      num.at(a) = b;
    }
  }
  if (ans == true) {
    for (int i = 1; i < 4; i++) {
      cout << num.at(i);
    }
  } else
    cout << -1;
  cout << endl;
  return 0;
}
