#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M, ans;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < (M); ++i) {
    cin >> s.at(i) >> c.at(i);
  }
  int x = 0;
  int xx = 0;
  int xxx = 0;
  if (N == 1) {
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) == 1) {
        ans = c.at(i);
      }
    }
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) > 1) {
        ans = -1;
      }
    }
  }
  if (N == 2) {
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) == 1) {
        xx = c.at(i);
      }
      if (s.at(i) == 2) {
        x = c.at(i);
      }
    }
    ans = xx * 10 + x;
    if (xx == 0) {
      ans = -1;
    }
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) > 2) {
        ans = -1;
      }
    }
  }
  if (N == 3) {
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) == 1) {
        xxx = c.at(i);
      }
      if (s.at(i) == 2) {
        xx = c.at(i);
      }
      if (s.at(i) == 3) {
        x = c.at(i);
      }
    }
    ans = xxx * 100 + xx * 10 + x;
    if (xxx == 0) {
      ans = -1;
    }
    for (int i = 0; i < (M); ++i) {
      if (s.at(i) > 3) {
        ans = -1;
      }
    }
  }
  for (int i = 0; i < (M); ++i) {
    for (int j = 0; j < (M); ++j) {
      if ((i != j) && (s.at(i) == s.at(j)) && (c.at(i) != c.at(j))) {
        ans = -1;
      }
    }
  }
  for (int i = 0; i < (M); ++i) {
    if ((N != 1) && (s.at(i) == 1) && (c.at(i) == 0)) {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
