#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
using V = vector<T>;
using Graph = vector<vector<int>>;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
signed main() {
  int n, m;
  cin >> n >> m;
  V<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  V<set<int>> st(n);
  for (int i = 0; i < m; i++) st[s[i] - 1].insert(c[i]);
  bool ok = 1;
  for (int i = 0; i < n; i++) {
    if (st[i].size() > 1) ok = 0;
  }
  string t;
  if (ok) {
    for (int i = 0; i < n; i++) {
      if (i == 0 && !st[i].empty() && *begin(st[i]) == 0)
        ok = 0;
      else if (i == 0) {
        if (st[i].size() == 0)
          t += '1';
        else
          t += to_string(*begin(st[i]));
      } else {
        if (st[i].size() == 0)
          t += '0';
        else
          t += to_string(*begin(st[i]));
      }
    }
  }
  if (ok)
    cout << t << endl;
  else
    cout << -1 << endl;
}
