#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max() / 4;
const int n_max = 1e5 + 10;
int main() {
  bool ok = true;
  long long n, m;
  cin >> n >> m;
  string str(n, 'a');
  for (long long i = 0; i < (long long)(m); i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (str[s] != 'a' && str[s] != '0' + c) {
      ok = false;
      break;
    }
    str[s] = '0' + c;
  }
  if (str[0] == 'a' || str[0] == '0') ok = false;
  for (long long i = 0; i < (long long)(n); i++)
    if (str[i] == 'a') str[i] = '0';
  cout << (ok ? str : "-1") << endl;
  ;
}
