#include <bits/stdc++.h>
using namespace std;
int main() {
  int M, N;
  int sc[5][2];
  int ans[3]{-1, -1, -1};
  bool error{false};
  int ans_num{0};
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> sc[i][0] >> sc[i][1];
    if ((ans[sc[i][0] - 1] != -1) and (ans[sc[i][0] - 1] != sc[i][1])) {
      error = true;
      cout << "error";
    } else {
      ans[sc[i][0] - 1] = sc[i][1];
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  if (error) {
    cout << -1;
  } else if ((ans[0] == 0) and (ans[1] == 0) and (ans[2] == 0)) {
    cout << -1;
  } else {
    ans_num = 100 * ans[0] + 10 * ans[1] + 1 * ans[2];
    cout << ans_num;
  }
  return 0;
}
