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