#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  int k[N];
  int result = 0;
  for (int a = 0; a < N; a++) {
    k[a] = 10;
  }
  for (int a = 0; a < M; a++) {
    cin >> s[a] >> c[a];
    k[s[a] - 1] = c[a];
    if (s[a] == 1 && c[a] == 0) {
      result = -1;
      break;
    }
  }
  for (int a = 0; a < M; a++) {
    for (int b = 0; b < a; b++) {
      if (s[a] == s[b] && c[a] != c[b]) {
        result = -1;
        break;
      }
    }
  }
  if (result != -1) {
    for (int a = 1; a < N; a++) {
      if (k[a] == 10) k[a] = 0;
    }
    if (k[0] == 10) k[0] = 1;
    for (int a = 0; a < N; a++) {
      if (k[a] == 10) k[a] = 0;
      result += pow(10, (N - a - 1)) * k[a];
    }
  }
  cout << result << endl;
}
