#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  string xp;
  for (int i = 0; i < n; ++i) xp += '0';
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (xp[s - 1] - '0' != c && xp[s - 1] != '0') {
      cout << -1 << endl;
      return 0;
    }
    if (c != xp[s - 1] - '0') xp[s - 1] = c + '0';
  }
  if (xp[0] == '0') {
    cout << -1 << endl;
  } else {
    cout << xp << endl;
  }
  return 0;
}
