#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long s[5];
long long c[5];
long long v[4];
int main() {
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < 4; i++) v[i] = -1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (n > m) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if (v[s[i]] != -1) {
      if (v[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      v[s[i]] = c[i];
    }
  }
  for (int i = 1; i < 4; i++) {
    if (v[i] == -1) {
      v[i] = 0;
    }
  }
  if (n == 3 && v[1] == 0 || n == 2 && v[1] == 0 && v[2] == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << v[1] << v[2] << v[3] << endl;
  return 0;
}
