#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  map<int, int> mp;
  mp[1] = -1;
  mp[2] = -1;
  mp[3] = -1;
  int digit[4];
  for (int i = 0; i < (4); ++i) {
    digit[i] = -1;
  }
  vector<pair<int, int> > p(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (m); ++i) {
    if (digit[s[i]] != -1 && digit[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    digit[s[i]] = c[i];
  }
  if (n != 1 && digit[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (digit[1] == -1 && digit[2] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int answer = 0;
  if (n == 3) {
    if (digit[1] != -1) {
      answer += digit[1] * 100;
    }
    if (digit[2] != -1) {
      answer += digit[2] * 10;
    }
    if (digit[3] != -1) {
      answer += digit[3];
    }
  }
  if (n == 2) {
    if (digit[1] != -1) {
      answer += digit[1] * 10;
    }
    if (digit[2] != -1) {
      answer += digit[2];
    }
  }
  if (n == 1) {
    if (digit[1] != -1) {
      answer += digit[1];
    }
  }
  string st = to_string(answer);
  if (st.length() != n) {
    cout << -1 << endl;
    return 0;
  }
  cout << answer << endl;
  return 0;
}
