#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, si, ci;
  cin >> n >> m;
  int s[n + 1];
  memset(s, -1, sizeof(s));
  bool isok = true;
  for (int i = 0; i < m; i++) {
    cin >> si >> ci;
    if (s[si] == -1) {
      s[si] = ci;
    } else {
      if (s[si] != ci) {
        isok = false;
      }
    }
  }
  if (isok) {
    string result = "";
    for (int i = 1; i <= n; i++) {
      if (s[i] == -1) {
        result += "0";
      } else {
        result += (48 + s[i]);
      }
    }
    cout << result;
  } else {
    cout << -1;
  }
}
