#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> a{10, 10, 10};
  ;
  for (ll i = 0; i < m; ++i) cin >> s[i] >> c[i];
  ;
  for (ll i = 0; i < m; ++i) {
    a[s[i] - 1] = min(a[s[i] - 1], c[i]);
  };
  for (ll i = 0; i < n; ++i) {
    if (a[i] == 10) {
      a[i] = 0;
    }
  }
  if (a[0] == 0) {
    puts("-1");
  } else {
    ;
    for (ll i = 0; i < n; ++i) {
      cout << a[i];
    }
  }
}
