#include <bits/stdc++.h>
using namespace std;
int n;
int m;
void solve() {
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (auto&& i : a) {
    cin >> i.first >> i.second;
    i.first--;
  }
  sort(a.begin(), a.begin());
  vector<int> ans(n, -1);
  for (auto&& i : a) {
    int& cur = ans[i.first];
    if (cur == -1) {
      cur = i.second;
      continue;
    }
    if (i.first == 0 && i.second == 0) continue;
    cur = min(cur, i.second);
  }
  for (int i = 0; i < n; ++i) ans[i] = max(ans[i], 0);
  if (n > 1 && ans[0] == 0) {
    cout << -1 << '\n';
    return;
  }
  for (auto&& i : ans) cout << i;
  cout << '\n';
}
int main() {
  int t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  while (t--) solve();
}
