#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, flag = 0, flag2 = 1, temp1 = 1000, temp2 = 0, temp3 = 1000, sum = 0;
  cin >> n >> m;
  int a[6], b[6], c[6];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    cin >> b[i];
    if (a[i] == 1 && flag == 0) {
      if (b[i] == 0)
        flag = 1;
      else if (temp1 == 1000) {
        temp1 = b[i];
        sum += b[i] * (pow(10, n - 1));
      } else if (b[i] != temp1)
        flag = 1;
      flag2 = 0;
    }
    if (a[i] == 2 && flag == 0) {
      if (b[i] < temp2) {
        sum += (b[i] * pow(10, n - 2));
        temp2 = b[i];
      }
    }
    if (a[i] == 3 && flag == 0) {
      if (b[i] < temp3) {
        sum += b[i];
        temp3 = b[i];
      }
    }
  }
  if (flag == 1 || flag2 == 1)
    cout << -1;
  else {
    cout << sum;
  }
  return 0;
}
