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