#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, *s, *c, *r, result, flag, temp;
  int i, j, k;
  cin >> N >> M;
  s = new int[M];
  c = new int[M];
  r = new int[M];
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    r[i] = 0;
  }
  if (N != 1)
    result = pow(10, N - 1) + 1;
  else
    result = 0;
  for (i = 1; i <= N; i++) {
    flag = 0;
    for (j = 0; j < M; j++) {
      if (i == s[j]) {
        if (flag == 0) {
          flag = 1;
          temp = c[j];
        } else {
          if (temp != c[j]) {
            result = -1;
            break;
          } else {
            flag = 2;
          }
        }
      }
      if (i == 1 && c[j] == 0) {
        result = -1;
        break;
      }
      if (i == s[j] && flag == 1) {
        if (i == 1)
          result += int(pow(10, N - 1) + 1) * (c[j] - 1);
        else
          result += int(pow(10, N - i)) * (c[j]);
      }
    }
  }
  cout << result;
}
