#include <bits/stdc++.h>
using namespace std;
int Digit(int x) {
  int counter = 0;
  while (x > 0) {
    x /= 10;
    counter++;
  }
  return counter;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<pair<int, int> > sc;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  int S;
  bool ok = true;
  for (auto p : sc) {
    for (auto q : sc) {
      if (p.first == q.first && p.second != q.second)
        ok = false;
      else if (p.first > N)
        ok = false;
    }
  }
  if (N == 1) {
    int a = 0;
    for (auto p : sc) a = p.second;
    S = a;
  } else if (N == 2) {
    int a = 0, b = 0;
    for (auto p : sc) {
      if (p.first == 1)
        a = p.second;
      else if (p.first == 2)
        b = p.second;
    }
    S = 10 * a + b;
    if (Digit(S) != 2) ok = false;
  } else {
    int a = 0, b = 0, c = 0;
    for (auto p : sc) {
      if (p.first == 1)
        a = p.second;
      else if (p.first == 2)
        b = p.second;
      else if (p.first == 3)
        c = p.second;
    }
    S = 100 * a + 10 * b + c;
    if (Digit(S) != 3) ok = false;
  }
  if (!ok) S = -1;
  cout << S << endl;
}
