#include <bits/stdc++.h>
int const MOD = 1e9 + 7;
using namespace std;
int main() {
  int n, m;
  vector<int> v(n);
  cin >> n >> m;
  vector<pair<int, int>> doSort(m);
  for (int i = 0; i < m; i++) {
    cin >> doSort[i].first >> doSort[i].second;
  }
  sort(doSort.begin(), doSort.end(),
       [](pair<int, int> a, pair<int, int> b) { return b.second < a.second; });
  vector<int> ans(n, -1);
  for (auto i : doSort) {
    ans[i.first - 1] = i.second;
  }
  if (ans[0] == -1 || ans[0] == 0 && n != 1)
    cout << -1 << '\n';
  else
    for (int &i : ans) {
      if (i == -1) i = 0;
      cout << i;
    }
  cout << '\n';
}
