#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  map<int, int> num;
  for (long long i = 0; i < (long long)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (s > N) {
      cout << -1 << endl;
    }
    if (num.count(s)) {
      if (num.at(s) != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      num.emplace(s, c);
    }
  }
  if (M == 0) {
    switch (N) {
      case 1:
        cout << 0 << endl;
        return 0;
      case 2:
        cout << 10 << endl;
        return 0;
      case 3:
        cout << 100 << endl;
        return 0;
    }
  }
  if (N > 1 && num.count(1) && num.at(1) == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (num.count(1) && num.at(1)) {
    cout << num.at(1);
  } else {
    cout << 1;
  }
  if (N > 1) {
    if (num.count(2) && num.at(2)) {
      cout << num.at(2);
    } else {
      cout << 0;
    }
  }
  if (N > 2) {
    if (num.count(3) && num.at(3)) {
      cout << num.at(3);
    } else {
      cout << 0;
    }
  }
  return 0;
}
