#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  int b1, b2;
  bool check = true;
  for (int i = 0; i < M; i++) {
    cin >> b1 >> b2;
    if (m.find(b1) == m.end()) {
      m[b1] = b2;
    } else {
      if (m[b1] != b2) {
        check = false;
      }
    }
  }
  if (!check) {
    cout << -1 << endl;
    return 0;
  }
  if (m.find(1) != m.end()) {
    if (m[1] == 0) {
      if (N != 1) {
        cout << -1 << endl;
        return 0;
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  string num;
  for (int i = 1; i <= N; i++) {
    if (m.find(1) != m.end()) {
      num += '0' + m[i];
    } else {
      num += '0';
    }
  }
  cout << num << endl;
}
