#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long num, tries, a, b, decide = 0, fin = 0;
  cin >> num >> tries;
  vector<long long> list;
  for (long long i = 0; i < num; i++) {
    list.push_back(99);
  }
  for (long long i = 0; i < tries; i++) {
    cin >> a >> b;
    if (a <= 0 || a > num) {
      cout << -1;
      decide = 1;
      break;
    }
    if (list[a - 1] == 99) {
      list[a - 1] = b;
    } else if (list[a - 1] != b) {
      cout << -1;
      decide = 1;
      break;
    }
  }
  for (long long i = 0; i < num; i++) {
    if (decide == 0) {
      if (list[0] == 99) {
        list[0] = 1;
      }
      if (list[i] == 99) {
        list[i] = 0;
      }
    } else {
      break;
    }
  }
  for (long long i = 0; i < num; i++) {
    if (decide == 0) {
      fin += list[i] * pow(10, num - i - 1);
    } else {
      break;
    }
  }
  if (decide == 0) {
    cout << fin;
  }
}
