#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int n, m;
  bool flag = true;
  cin >> n >> m;
  map<int, int> mp;
  int s, c;
  for (int i = 0; i < (m); i++) {
    cin >> s >> c;
    if (mp[s] != c && mp[s] != 0) {
      flag = false;
    } else {
      mp[s] = c;
    }
  }
  if (n == 3 && mp[1] == 0) {
    flag = false;
  }
  if (n == 2 && mp[1] == 0) {
    flag = false;
  }
  if (n == 2 && (mp[2] == 0 || mp[1] == 0)) {
    flag = false;
  }
  if (n == 1 && (mp[2] == 0 || mp[1] == 0)) {
    flag = false;
  }
  int ans = mp[1] * 100 + mp[2] * 10 + mp[3];
  if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
