#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  int s, c;
  vector<int> a(n, 2147483647);
  bool ans = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s--;
    a[s] = min(a[s], c);
  }
  if ((a[0] == 0 || a[0] == 2147483647) && n != 1) ans = false;
  if (ans) {
    for (auto p : a) {
      if (p != 2147483647)
        cout << p;
      else
        cout << "0";
    }
  } else
    cout << "-1";
  cout << "\n";
}
