#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  int prob = 1;
  int flag = 0;
  vector<int> ansvec(N);
  int ans = 0;
  for (int i = 0; i < M - 1; i++) {
    for (int k = i + 1; k < M; k++) {
      if (s[i] == s[k]) {
        if (c[i] != c[k]) {
          prob = 0;
          ans = -1;
        }
      }
    }
  }
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1) {
        if (c[i] == 0) {
          prob = 0;
          ans = -1;
        }
      }
    }
  }
  if (N == 1 && prob == 1) {
    ans = c[0];
  }
  if (N > 1 && prob == 1) {
    for (int i = 0; i < M; i++) {
      for (int k = 1; k <= N; k++) {
        if (s[i] == k) {
          if (k == 1) {
            flag = 1;
          }
          ansvec[k - 1] = c[i];
        }
      }
    }
    if (flag == 0) {
      ansvec[0] = 1;
    }
    for (int i = 0; i < N; i++) {
      ans += ansvec[i] * pow(10, N - i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
