#include <bits/stdc++.h>
using namespace std;
int main() {
  int digitnum;
  int opnum;
  cin >> digitnum >> opnum;
  vector<int> digit_arr(digitnum, 0);
  vector<int> update_check(digitnum, 0);
  while (opnum > 0) {
    int s;
    int c;
    cin >> s >> c;
    if (digit_arr[s - 1] > c) {
      digit_arr[s - 1] = c;
      update_check[s - 1] = 1;
    } else if (digit_arr[s - 1] == 0) {
      if (update_check[s - 1] == 0) {
        digit_arr[s - 1] = c;
        update_check[s - 1] = 1;
      }
    }
    opnum--;
  }
  if (digitnum > 1) {
    if (digit_arr[0] == 0)
      cout << -1 << endl;
    else {
      int sum = 0;
      int mul = 1;
      for (int i = digit_arr.size() - 1; i >= 0; i--) {
        sum += digit_arr[i] * mul;
        mul *= 10;
      }
      cout << sum << endl;
    }
  } else
    cout << digit_arr[0] << endl;
  return 0;
}
