#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int s[5], c[5];
  int v = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < N; i++) {
    int tmp = -1;
    for (int j = 0; j < M; j++) {
      if (s[j] != i + 1) continue;
      if (i == 0 && c[j] == 0 && 1 < N) {
        v = -1;
        break;
      }
      if (tmp == -1) {
        tmp = c[j];
        continue;
      }
      if (tmp != c[j]) {
        v = -1;
        break;
      }
    }
    if (v == -1) break;
    if (tmp == -1) {
      if (i == 0)
        tmp = 1;
      else
        tmp = 0;
    }
    v = v * 10 + tmp;
  }
  cout << v << endl;
}
