#include <bits/stdc++.h>
using namespace std;
bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
  return arg1.first > arg2.first;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(3, -1);
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (a.at(s) != -1 && a.at(s) != c) {
      cout << -1 << endl;
      return 0;
    } else
      a.at(s) = c;
  }
  for (int i = 0; i < n; i++) {
    if (n != 1 && a.at(0) == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n == 1 && a.at(0) == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (i == 0 && a.at(i) == -1) {
      cout << 1;
      continue;
    }
    if (i != 0 && a.at(i) == -1) {
      cout << 0;
      continue;
    }
    cout << a.at(i);
  }
  cout << endl;
  return 0;
}
