#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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n, 1e9);
  for (ll i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    chmin(x[s], c);
  }
  int ans = 0;
  if (n == 1) {
    ans = x[0];
  } else {
    for (ll i = 0; i < n; i++) {
      if (i == 0 and x[0] == 0) {
        cout << -1;
        return 0;
      }
      ans *= 10;
      if (x[i] != 1e9) {
        ans += x[i];
      }
    }
  }
  cout << ans;
}
