#include <bits/stdc++.h>
using namespace std;
int N, M;
int res[3];
bool setflag[3];
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (setflag[s - 1] && res[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    res[s - 1] = c;
    setflag[s - 1] = true;
  }
  if (res[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << res[0] * 100 + res[1] * 10 + res[2] << endl;
  return 0;
}
