#include <bits/stdc++.h>
using namespace std;
void sol(int n, int m) {
  map<int, int> hs;
  hs[1] = 10;
  hs[2] = 10;
  hs[3] = 10;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 and b != 0 and hs[a] > b) {
      hs[a] = b;
    } else {
      if (a != 1 and hs[a] > b) {
        hs[a] = b;
      }
    }
  }
  if (hs[1] == 10) {
    hs[1] = 0;
  }
  if (hs[2] == 10) {
    hs[2] = 0;
  }
  if (hs[2] == 10) {
    hs[2] = 0;
  }
  int res = 0;
  if (n == 1) {
    if (hs[1] == 0) {
      cout << -1;
      return;
    }
    cout << hs[1];
    return;
  }
  if (n == 2) {
    if (hs[1] == 0) {
      cout << -1;
      return;
    }
    if (hs[1]) {
      res = res * 10 + hs[1];
    }
    if (hs[2]) {
      res = res * 10 + hs[2];
    } else {
      res = res * 10 + 0;
    }
    cout << res;
    return;
  }
  if (n == 3) {
    if (hs[1] == 0) {
      cout << -1;
      return;
    }
    if (hs[1]) {
      res = res * 10 + hs[1];
    }
    if (hs[2]) {
      res = res * 10 + hs[2];
    } else {
      res = res * 10 + 0;
    }
    if (hs[3]) {
      res = res * 10 + hs[3];
    } else {
      res = res * 10 + 0;
    }
    cout << res;
  }
}
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  sol(n, m);
}
