#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] = {10, 10, 10, 10};
  bool zero_flag = false;
  for (int i = 0; i < M; i++) {
    if (digit[s[i]] == 10) {
      digit[s[i]] = c[i];
    } else if (digit[s[i] > c[i]])
      digit[s[i]] = c[i];
    else
      break;
  }
  if (N == 1) {
    if (digit[1] == 10 && digit[2] == 10)
      cout << digit[3] << endl;
    else
      cout << -1 << endl;
  } else {
    if (digit[3] == 10) digit[3] = 0;
    if (N == 2) {
      if (digit[1] != 10)
        cout << "-1" << endl;
      else {
        if (digit[2] == 10)
          cout << "-1" << endl;
        else {
          ans = digit[2] * 10 + digit[3];
          cout << ans << endl;
        }
      }
    } else {
      if (digit[1] == 0)
        cout << "-1" << endl;
      else {
        if (digit[1] == 10)
          cout << "-1" << endl;
        else {
          if (digit[2] == 10) digit[2] = 0;
          ans = digit[1] * 100 + digit[2] * 10 + digit[3];
          cout << ans << endl;
        }
      }
    }
  }
  return 0;
}
