#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  map<int, int> sc;
  vector<int> s(m);
  vector<int> c(m);
  sc[1] = 0;
  sc[2] = 0;
  sc[3] = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    sc[s[i]] = c[i];
    if (s[i] > n) {
      cout << -1;
      return 0;
    }
  }
  if (n >= 2) {
    if (sc[1] == 0) {
      cout << -1;
      return 0;
    }
  }
  if (s[0] == s[1])
    if (c[0] != c[1]) {
      cout << -1;
      return 0;
    } else if (s[0] == s[2])
      if (c[0] != c[2]) {
        cout << -1;
        return 0;
      } else if (s[2] == s[1])
        if (c[2] != c[1]) {
          cout << -1;
          return 0;
        }
  if (n == 1) {
    if (m == 0) {
      cout << 0;
    }
    cout << sc[1];
    return 0;
  } else if (n == 2) {
    if (sc[1] == 0) sc[1] = 1;
    if (sc[2] == 0) sc[2] = 0;
    cout << sc[1] << sc[2];
    return 0;
  } else if (n == 3) {
    if (sc[1] == 0) sc[1] = 1;
    if (sc[2] == 0) sc[2] = 0;
    if (sc[3] == 0) sc[3] = 0;
    cout << sc[1] << sc[2] << sc[3];
  }
  return 0;
}
