#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int digit[4] = {0, 0, 0, 0};
  bool zero_flag = false;
  for (int i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) zero_flag = true;
    if (digit[s[i]] == 0) {
      digit[s[i]] = c[i];
    } else if (digit[s[i] < c[i]])
      digit[s[i]] = c[i];
    else
      break;
  }
  if (N == 3) {
    if (digit[1] == 0)
      cout << "-1" << endl;
    else {
      ans = digit[1] * 100 + digit[2] * 10 + digit[3];
      cout << ans << endl;
    }
  } else if (N == 2) {
    if (digit[1] != 0)
      cout << "-1" << endl;
    else if (digit[2] == 0)
      cout << "-1" << endl;
    else {
      ans = digit[1] * 100 + digit[2] * 10 + digit[3];
      cout << ans << endl;
    }
  } else {
    if (digit[1] != 0 || digit[2] != 0)
      cout << "-1" << endl;
    else if (zero_flag)
      cout << 0 << endl;
    else {
      ans = digit[1] * 100 + digit[2] * 10 + digit[3];
      cout << ans << endl;
    }
  }
  return 0;
}
