#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[5], c[5];
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  bool x = false, y = false;
  for (int i = 0; i < m; ++i) {
    if (s[i] > n) {
      cout << -1;
      return 0;
    }
    if (!y && s[i] == 1 && c[i] == 0) {
      x = true;
    }
    if (x && s[i] == 1 && c[i] != 0) {
      x = false;
      y = true;
    }
  }
  if (x && !y) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1;
          return 0;
        }
      }
    }
  }
  bool f[3] = {};
  string r(n, '9');
  for (int i = 0; i < m; ++i) {
    if (r[s[i] - 1] > c[i]) {
      r[s[i] - 1] = ('0' + c[i]);
    }
    f[s[i] - 1] = true;
  }
  for (int i = 0; i < 3; ++i) {
    if (f[i] == false) r[i] = '0';
  }
  if (r[0] == '0') r[0] = 1;
  cout << r;
  return 0;
}
