#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  vector<int> ans(3, 0);
  bool flag = true;
  bool check = true;
  set<int> sdic;
  set<int> cdic;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (sdic.count(s) && cdic.count(c))
      continue;
    else if (sdic.count(s) && !cdic.count(c)) {
      flag = false;
      break;
    }
    ans[s - 1] = c;
    sdic.insert(s);
    cdic.insert(c);
  }
  if (ans[0] == 0 && ans[1] == ans[2] && ans[2] == ans[0]) check = false;
  if (flag && check) {
    for (int i = 3 - N; i < N; i++) {
      cout << ans[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
