#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M], j, b = 1, a, A = 0, B = 0, C = 0, D = 0;
  for (int i = 0; i < (int)M; i++) {
    j = i;
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0 && N != 1) {
      cout << -1 << endl;
      D++;
      break;
    }
    while (j > 0) {
      j--;
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        D++;
        break;
      }
      for (int d = 0; d < (int)N - s[i]; d++) {
        b *= 10;
      }
      if (s[i] == 1) {
        A = c[i] * b;
      }
      if (s[i] == 2) {
        B = c[i] * b;
      }
      if (s[i] == 3) {
        C = c[i] * b;
      }
      b = 1;
    }
  }
  a = (A + B + C);
  if (D == 0) {
    cout << a << endl;
  }
  return 0;
}
