#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<int> kaburi;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n != 1 && s[0] == 1 && c[0] == 0) {
    cout << -1;
    return 0;
  }
  int cand1 = -1;
  for (int i = 0; i < m; i++) {
    if (s[i] == 1) {
      if (cand1 != -1) {
        if (cand1 != c[i]) {
          cout << -1;
          return 0;
        }
      } else {
        cand1 = c[i];
      }
    }
  }
  if (cand1 == -1) {
    cand1 = 0;
  }
  if (n == 1) {
    cout << cand1;
    return 0;
  }
  int cand2 = -1;
  for (int i = 0; i < m; i++) {
    if (s[i] == 2) {
      if (cand2 != -1) {
        if (cand2 != c[i]) {
          cout << -1;
          return 0;
        }
      } else {
        cand2 = c[i];
      }
    }
  }
  if (cand2 == -1) {
    cand2 = 0;
  }
  if (n == 2) {
    cout << cand1 * 10 + cand2;
    return 0;
  }
  int cand3 = -1;
  for (int i = 0; i < m; i++) {
    if (s[i] == 3) {
      if (cand3 != -1) {
        if (cand3 != c[i]) {
          cout << -1;
          return 0;
        }
      } else {
        cand3 = c[i];
      }
    }
  }
  if (cand3 == -1) {
    cand3 = 0;
  }
  if (n == 3) {
    cout << cand1 * 100 + cand2 * 10 + cand3;
    return 0;
  }
}
