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