#include <bits/stdc++.h>
using namespace std;
template <typename T>
void drop(const T &x) {
  cout << x << '\n';
  exit(0);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> s(m);
  for (int i = 0; i < m; ++i) cin >> s[i].first >> s[i].second;
  sort(s.begin(), s.end());
  if (n >= 2 && (s[0].first != 1 || s[0].second == 0)) drop(-1);
  for (int h = 1; h <= n; ++h) {
    int ans = 10;
    for (int i = 0; i < m; ++i) {
      if (s[i].first != h) continue;
      ans = min(ans, s[i].second);
    }
    cout << ans % 10;
  }
  cout << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) solve();
  return 0;
}
