#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int fact(int n);
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) res = res * i;
  return res;
}
int main() {
  int N = 0, M = 0;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  bool ans = true, flg = false;
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        ans = false;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0 && N != 1) {
      ans = false;
    }
  }
  int num[4] = {0, 9, 9, 9};
  int judge[4] = {0, 0, 0, 0};
  if (ans) {
    for (int i = 0; i < M; i++) {
      if (c[i] < num[s[i]]) {
        num[s[i]] = c[i];
        judge[s[i]] = 1;
      }
    }
    for (int i = 0; i < 4; i++) {
      if (judge[i] == 0) {
        if (i == 1) {
          num[i] = 1;
        } else {
          num[i] = 0;
        }
      }
    }
    cout << num[1] << num[2] << num[3] << endl;
  } else {
    cout << "-1" << endl;
  }
}
