#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  bool flag;
  cin >> N >> M;
  vector<int> S(M), C(M);
  vector<int> indices(M);
  string s = "";
  for (int i = 0; i < M; i++) {
    cin >> S[i];
    cin >> C[i];
  }
  iota(indices.begin(), indices.end(), 0);
  sort(indices.begin(), indices.end(),
       [&S](size_t i1, size_t i2) { return S[i1] < S[i2]; });
  if (S[*indices.end() - 1] > N || C[indices[0]] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < M; i++) {
    int prev = indices[i - 1];
    int now = indices[i];
    if (S[prev] == S[now]) {
      if (C[prev] != C[now]) {
        cout << -1 << endl;
        return 0;
      }
      flag = false;
    } else {
      int dif = -now + prev;
      s += to_string(C[prev]);
      for (int j = 0; j < dif; j++) {
        if (s == "")
          s += "1";
        else
          s += "0";
      }
      flag = true;
    }
  }
  if (flag) s += to_string(C[indices[M - 1]]);
  cout << s << endl;
  return 0;
}
