#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  char ci;
  int N, M, si;
  string num = "";
  cin >> N >> M;
  for (int i = 0; i < (int)(N); i++) num += "x";
  for (int i = 0; i < (int)(M); i++) {
    cin >> si >> ci;
    if (num.at(si - 1) != ci && num.at(si - 1) != 'x') {
      cout << "-1\n";
      return (0);
    }
    if (si == 1 && ci == '0' && N != 1) {
      cout << "-1\n";
      return (0);
    }
    num.at(si - 1) = ci;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (num.at(i) == 'x') num.at(i) = '0';
  }
  cout << num << "\n";
}
