#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c;
  int result = -1;
  bool end = false;
  vector<bool> check(3, false);
  cin >> N >> M;
  vector<int> num(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (s == 0) {
      end = true;
      break;
    }
    if (!check.at(s - 1)) {
      check.at(s - 1) = true;
    } else if (check.at(s - 1) && !(num.at(s - 1) == c)) {
      end = true;
      break;
    }
    num.at(s - 1) = c;
  }
  if (!(end)) {
    result = 0;
    if (N == 1) {
      if (num.at(0) != -1) {
        result += num.at(0);
      } else if (num.at(0) == -1) {
        result = 0;
      }
      cout << result << endl;
    } else if (N == 2) {
      if (num.at(0) != -1) {
        result += num.at(0) * 10;
      }
      if (num.at(1) != -1) {
        result += num.at(1);
      }
      cout << result << endl;
    } else if (N == 3) {
      if (num.at(0) != -1) {
        result += num.at(0) * 100;
      }
      if (num.at(1) != -1) {
        result += num.at(1) * 10;
      }
      if (num.at(2) != -1) {
        result += num.at(2);
      }
      cout << result << endl;
    }
  } else if (end == true) {
    cout << result << endl;
  }
}
