#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (m.count(s) != 0) {
      if (m[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
    m[s] = c;
  }
  for (int i = 1; i < N + 1; i++) {
    if (m.count(i) == 0) {
      if (i == 1) {
        if (N == 0) {
          cout << 0;
          continue;
        } else {
          cout << -1 << endl;
          return 0;
        }
      }
      cout << 0;
      continue;
    }
    if (m[i] == 0) {
      if (i == 1 && N == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << m[i];
  }
  cout << endl;
  return 0;
}
