#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int dig, req;
  int rd[5], rn[5];
  cin >> dig >> req;
  for (int i = 0; i < (req); i++) {
    cin >> rd[i] >> rn[i];
    rd[i]--;
  }
  int num[3];
  memset(num, -1, sizeof(num));
  for (int i = 0; i < (req); i++) {
    if (num[rd[i]] != -1 && rn[i] != num[rd[i]]) {
      cout << "-1";
      return 0;
    }
    num[rd[i]] = rn[i];
  }
  for (int i = 0; i < (3); i++)
    if (num[i] == -1) num[i] = 0;
  if (num[0] != 0)
    cout << num[0] << num[1] << num[2];
  else if (num[0] == 0 && num[1] != 0)
    cout << num[1] << num[2];
  else
    cout << num[2];
  return 0;
}
