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