#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  string s = "";
  cin >> n >> m;
  for (int i = 0; i < n; i++) s += '0';
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    char bb = (char)b + '0';
    a--;
    if (s[a] == '0' || s[a] == bb) {
      s[a] = bb;
    } else
      return cout << -1, 0;
  }
  bool ok = false;
  for (int i = 0; i < n; i++) {
    if (s[i] != '0') ok = true;
  }
  if (!ok) return cout << -1, 0;
  cout << s;
  return 0;
}
