#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> kazu(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> kazu[i].first >> kazu[i].second;
  }
  int keta1 = 1;
  int count1 = 0;
  int keta2 = 0;
  int count2 = 0;
  int keta3 = 0;
  int count3 = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (kazu[i].first == 1) {
      if (count1 == 0) {
        keta1 = kazu[i].second;
        count1++;
      } else {
        if (keta1 != kazu[i].second) {
          cout << -1 << endl;
          return 0;
        }
      }
    } else if (kazu[i].first == 2) {
      if (count2 == 0) {
        keta2 = kazu[i].second;
        count2++;
      } else {
        if (keta2 != kazu[i].second) {
          cout << -1 << endl;
          return 0;
        }
      }
    } else {
      if (count3 == 0) {
        keta3 = kazu[i].second;
        count3++;
      } else {
        if (keta3 != kazu[i].second) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  if (n == 1) {
    if (keta1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 1; i <= 9; i++) {
      cout << keta1 << endl;
    }
  }
  if (n == 2) {
    for (int i = 10; i <= 99; i++) {
      int a, x1, x2;
      a = i;
      x2 = a % 10;
      a /= 10;
      x1 = a % 10;
      if (keta1 == x1 && keta2 == x2) {
        cout << keta1 << keta2 << endl;
        return 0;
      }
    }
  }
  if (n == 3) {
    for (int i = 100; i <= 999; i++) {
      int a, x1, x2, x3;
      a = i;
      x3 = a % 10;
      a /= 10;
      x2 = a % 10;
      a /= 10;
      x1 = a % 10;
      if (keta1 == x1 && keta2 == x2 && keta3 == x3) {
        cout << keta1 << keta2 << keta3 << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
