#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long MOD = 1000000000 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  vector<int> ans(n + 1, -1);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (ans[s] == -1) {
      ans[s] = c;
    } else {
      ans[s] = min(ans[s], c);
    }
  }
  if (n == 1 && ans[1] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (ans[1] == -1 || ans[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    if (ans[i] == -1) {
      cout << ans[i] + 1;
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}
