#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> m;
  int n, q, a, b, flag = 1;
  cin >> n >> q;
  string s;
  s.resize(n);
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    if (m[i]) {
      if (b == (s[a - 1] - '0')) {
        s[a - 1] = '0' + b;
        m[a - 1] = 1;
      } else {
        flag = 0;
        break;
      }
    } else {
      s[a - 1] = '0' + b;
      m[a - 1] = 1;
    }
  }
  if (flag) {
    if (s[0] == '0' && n != 1) {
      cout << -1 << "\n";
    } else {
      for (int i = 0; i < n; i++) {
        if (!m[i]) {
          s[i] = rand() % 10 + '0';
          m[i] = 1;
        }
      }
      cout << s << "\n";
    }
  } else {
    cout << -1 << "\n";
  }
}
