#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> d;
  vector<int> s(m), c(m);
  string ans = "";
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (d.count(s[i]) && d[s[i]][0] != c[i]) {
      ans = "-1";
    } else if (s[i] == 0 && c[i] == 0) {
      ans = "-1";
    }
    d[s[i]].push_back(c[i]);
  }
  if (ans != "-1") {
    for (int i = 0; i < (n); i++) {
      if (d.count(i)) {
        ans += to_string(d[i][0]);
      } else {
        ans += "0";
      }
    }
  }
  cout << ans << endl;
  return 0;
}
