#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans = 0;
  int flag1, flag2, flag3;
  flag1 = 0;
  flag2 = 0;
  flag3 = 0;
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && flag1 == 0) {
      ans += c[i] * pow(10, N - 1);
      flag1++;
    }
    if (s[i] == 2 && flag2 == 0) {
      ans += c[i] * pow(10, N - 2);
      flag2++;
    }
    if (s[i] == 3 && flag3 == 0) {
      ans += c[i];
      flag3++;
    }
  }
  if (flag1 == 0) {
    if (N == 2) ans += 10;
    if (N == 3) ans += 100;
  }
  cout << ans << endl;
}
