#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > c(m);
  set<int> S;
  set<int> C;
  for (int i = 0; i < m; i++) {
    cin >> c[i].first >> c[i].second;
  }
  vector<int> ans(100, 0);
  sort(c.begin(), c.end());
  for (int i = 0; i < m; i++) {
    if (S.find(c[i].first) == S.end()) {
      ans[c[i].first] = c[i].second;
    }
    if (S.find(c[i].first) != S.end()) {
      if (C.find(c[i].second) == C.end()) {
        cout << -1 << '\n';
        return (0);
      }
    }
    S.insert(c[i].first);
    C.insert(c[i].second);
  }
  bool flag = true;
  int si = ans.size();
  for (int i = 1; i < n + 1; i++) {
    if (ans[i] == 0 && i != n && flag) {
      cout << -1 << '\n';
      return (0);
    }
    cout << ans[i];
    flag = false;
  }
  return (0);
}
