#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  string out;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    out[i] = '_';
  }
  unordered_map<int, int> map;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (s > n) {
      cout << -1;
      exit(0);
    } else if (map.find(s) != map.end()) {
      if (map.find(s)->second != c) {
        cout << -1;
        exit(0);
      }
    } else {
      map[s] = c;
    }
  }
  for (auto x : map) {
    out[x.first - 1] = (char)x.second;
  }
  for (int i = 0; i < n; i++) {
    if (out[i] == '_') {
      out[i] = '0';
    }
  }
  cout << out;
}
