#include <bits/stdc++.h>
using namespace std;
bool output(int a, int c) {
  if (a == c) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > A(M);
  for (int i = 0; i < (int)(M); i++) cin >> A.at(i).first >> A.at(i).second;
  int start = 1;
  for (int i = 0; i < (int)(N - 1); i++) start = start * 10;
  bool ok = false;
  for (int i = start; i < start * 10; i++) {
    bool l = true;
    for (int j = 0; j < M; j++) {
      int s = A.at(j).first, c = A.at(j).second;
      int a = i;
      if (s == 1) {
        if (start == 1) {
          if (output(a, c) == false) l = false;
        } else if (start == 10) {
          a /= 10;
          if (output(a, c) == false) l = false;
        } else {
          a /= 100;
          if (output(a, c) == false) l = false;
        }
      } else if (s == 2) {
        if (start == 1) {
          l = false;
        } else if (start == 10) {
          a %= 10;
          if (output(a, c) == false) l = false;
        } else {
          a %= 100;
          a /= 10;
          if (output(a, c) == false) l = false;
        }
      } else {
        if (start == 1) {
          l = false;
        } else if (start == 10) {
          l = false;
        } else {
          a %= 100;
          a %= 10;
          if (output(a, c) == false) l = false;
        }
      }
    }
    if (l) {
      ok = true;
      cout << i << endl;
      return 0;
    }
  }
  if (ok == false) {
    cout << -1 << endl;
  }
}
