#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<P> sc(m);
  if (m != 0) {
    for (int i = 0; i < (m); i++) {
      cin >> sc[i].first >> sc[i].second;
    }
    for (int i = 0; i < (m); i++) {
      if (n != 1 && sc[i].first == 1 && sc[i].second == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    for (int i = 0; i < (m); i++) {
      for (int j = 0; j < (m); j++) {
        if (i != j && sc[i].first == sc[j].first &&
            sc[i].second != sc[j].second && sc[i].first <= n) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    sort((sc).begin(), (sc).end());
  }
  string ans = "";
  int count = 1;
  bool ok = false;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      if (sc[j].first == i + 1) {
        cout << sc[j].second;
        ok = true;
        break;
      }
    }
    if (!ok) cout << 1;
    ok = false;
  }
  cout << endl;
  return 0;
}
