#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N);
  vector<int> c(N);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  vector<bool> dup(N + 1);
  vector<int> x(N + 1);
  for (int i = 0; i < (N + 1); i++) {
    dup[i] = false;
  }
  for (int i = 0; i < M; i++) {
    if (s[i] > N || s[i] < 1 || c[i] > 9 || c[i] < 0) {
      cout << -1 << endl;
      return 0;
    } else {
      if ((dup[s[i]] == true) && (c[i] != x[s[i]])) {
        cout << -1 << endl;
        return 0;
      } else if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        dup[s[i]] = true;
        x[s[i]] = c[i];
      }
    }
  }
  for (int i = 1; i < N + 1; i++) {
    if (!dup[i]) {
      if (i == 1) {
        if (N == 1) {
          x[i] = 0;
        } else {
          x[i] = 1;
        }
      } else {
        x[i] = 0;
      }
    }
  }
  for (int i = 1; i < N + 1; i++) {
    cout << x[i];
  }
  cout << endl;
}
