#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (N == 2 && M == 0) {
    cout << 10 << endl;
    return 0;
  }
  if (N == 3 && M == 0) {
    cout << 100 << endl;
    return 0;
  }
  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }
  int kotae = 0;
  bool hantei = false;
  int count1 = 0;
  int count2 = 0;
  int count3 = 0;
  int keta1 = 0;
  int keta2 = 0;
  int keta3 = 0;
  int kotae1 = 0;
  int kotae2 = 0;
  int kotae3 = 0;
  int sum = 0;
  for (int i = 0; i < M; i++) {
    if (S.at(i) == 1) {
      if (count1 > 0) {
        if (keta1 != C.at(i)) {
          cout << -1 << endl;
          return 0;
        }
      }
      count1++;
      keta1 = C.at(i);
      kotae1 = C.at(i) * 100;
      if (C.at(i) == 0) hantei = true;
    }
    if (S.at(i) == 2) {
      if (count2 > 0) {
        if (keta2 != C.at(i)) {
          cout << -1 << endl;
          return 0;
        }
      }
      count2++;
      keta2 = C.at(i);
      kotae2 = C.at(i) * 10;
      if (C.at(i) == 0) hantei = true;
    }
    if (S.at(i) == 3) {
      if (count3 > 0) {
        if (keta3 != C.at(i)) {
          cout << -1 << endl;
          return 0;
        }
      }
      count3++;
      keta3 = C.at(i);
      kotae3 = C.at(i);
      if (C.at(i) == 0) hantei = true;
    }
  }
  sum = kotae1 + kotae2 + kotae3;
  if (hantei == false) {
    if (sum == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 3) {
    if (sum < 100) {
      kotae1 = 100;
    }
  } else if (N == 2) {
    if (sum < 10) {
      kotae2 = 10;
    }
  }
  sum = kotae1 + kotae2 + kotae3;
  cout << sum << endl;
  return 0;
}
