#include <bits/stdc++.h>
using namespace std;
int digit(int b) {
  int i = 0, x, f = 0;
  if (b % 10 == 0) f = 1;
  while (b != 0) {
    x = b % 10;
    b /= 10;
    i++;
  }
  if (f == 1) return i + 1;
  return i;
}
int main() {
  int n, m, s[6] = {0}, f = 0, flag = 0, c[6] = {0}, i, j, b = 0, x;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      f = 1;
      break;
    }
    if (s[i] > n) {
      f = 1;
      break;
    }
    for (j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        f = 1;
        break;
      } else if (s[i] == s[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      x = 1;
      for (int k = 1; k <= n - s[i]; k++) x *= 10;
      b += c[i] * x;
    } else if (f == 1) {
      break;
    } else {
      flag = 0;
    }
  }
  if (f == 1) {
    cout << -1;
    return 0;
  }
  if (digit(b) < n) {
    cout << 1;
    for (i = 2; i <= n - digit(b); i++) cout << 0;
    cout << b << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}
