#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int pos, num;
  string str;
  for (int(i) = (0); (i) < (n); (i)++) str += '0';
  string number = "0123456789";
  for (int(i) = (0); (i) < (m); (i)++) {
    cin >> pos >> num;
    pos--;
    if (str[pos] == '0' || str[pos] == number[num]) {
      str[pos] = number[num];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (str[0] == '0') {
    cout << -1 << endl;
  } else {
    cout << str << endl;
  }
  return 0;
}
