#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);
  for (int i = 0; i < (m); i++) {
    cin >> sc[i].first >> sc[i].second;
    if (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) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  sort((sc).begin(), (sc).end());
  string ans = "";
  int count = 1, idx = 0;
  while (count <= n) {
    if (count == sc[idx].first) {
      cout << sc[idx].second;
    } else {
      cout << 0;
    }
    count++;
    idx++;
  }
  cout << endl;
  return 0;
}
