#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<vector<int> > x(n);
  for (ll i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    x[s].push_back(c);
  }
  for (ll i = 0; i < n; i++) {
    if (x[i].size() == 0) {
      x[i].push_back(0);
    }
  }
  if (m == 0) {
    cout << -1;
    return 0;
  }
  int ans = 0;
  if (n == 1) {
    ans += *min_element((x[0]).begin(), (x[0]).end());
  } else {
    for (ll i = 0; i < n; i++) {
      if (i == 0 and *min_element((x[i]).begin(), (x[i]).end()) == 0) {
        cout << -1;
        return 0;
      }
      ans *= 10;
      ans += *min_element((x[i]).begin(), (x[i]).end());
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
