#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  vector<int> s;
  vector<int> c;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int si;
    int ci;
    cin >> si >> ci;
    s.push_back(si);
    c.push_back(ci);
  }
  int result[N];
  bool invalid = false;
  for (int i = 0; i < N; i++) {
    result[i] = -1;
  }
  for (int i = 0; i < s.size(); i++) {
    int si = s[i];
    int ci = c[i];
    if (M != 1 && si == 1 && ci == 0) {
      invalid = true;
      continue;
    }
    if (result[si - 1] != -1 && result[si - 1] != ci) {
      invalid = true;
      continue;
    }
    result[si - 1] = ci;
  }
  if (invalid) {
    cout << "-1" << endl;
  } else {
    for (int i = 0; i < N; ++i) {
      if (result[i] == -1) {
        if (i == 0) {
          if (M == 0) {
            cout << 0;
          } else {
            cout << 1;
          }
        } else {
          cout << 0;
        }
      } else {
        cout << result[i];
      }
    }
    cout << endl;
  }
  return 0;
}
