#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    sc.push_back(make_pair(c, s - 1));
  }
  int ans[n];
  bool state[n];
  memset(state, false, sizeof state);
  memset(ans, 0, sizeof ans);
  sort((sc).begin(), (sc).end());
  for (auto sci : sc) {
    if (state[sci.second] == false) {
      ans[sci.second] = sci.first;
      state[sci.second] = true;
    }
  }
  if ((ans[0] == 0 || state[0] == false) && n > 1) {
    cout << -1 << endl;
    return;
  } else {
    for (auto d : ans) {
      cout << d;
    }
    cout << '\n';
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
