#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, qq, s, c;
  map<int, int> mp;
  mp[1] = mp[2] = mp[3] = 0;
  cin >> n >> qq;
  bool chk = true;
  while (qq--) {
    cin >> s >> c;
    if (mp[s] != 0 && mp[s] != c) {
      chk = false;
    } else {
      mp[s] = c;
    }
  }
  if (chk) {
    if (n == 1) {
      if (mp[1] >= 0)
        cout << mp[1] << endl;
      else
        cout << "-1\n";
    } else if (n == 2) {
      if (mp[1] > 0 && mp[2] >= 0)
        cout << mp[1] << mp[2] << endl;
      else
        cout << "-1\n";
    } else if (n == 3) {
      if (mp[1] > 0 and mp[2] >= 0 and mp[3] >= 0)
        cout << mp[1] << mp[2] << mp[3] << endl;
      else
        cout << "-1\n";
    }
  } else
    cout << "-1\n";
  return 0;
}
