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