#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  vector<int> digit(3, -1);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (digit[s] != -1 && digit[s] != c) {
      cout << -1;
      return 0;
    }
    digit[s] = c;
  }
  if ((N == 2 || N == 3) && digit[0] == 0) {
    cout << -1;
    return 0;
  }
  int start = 0;
  int end = 10;
  if (N == 1) {
    cout << digit[0];
  } else if (N == 2) {
    for (int i = 10; i < 100; i++) {
      int digit1 = i / 10;
      int digit2 = i % 10;
      bool check1 = false;
      if (digit[0] == -1)
        check1 = true;
      else if (digit[0] == digit1)
        check1 = true;
      bool check2 = false;
      if (digit[1] == -1)
        check2 = true;
      else if (digit[1] == digit2)
        check2 = true;
      if (check1 && check2) {
        cout << i;
        return 0;
      }
    }
  } else if (N == 3) {
    for (int i = 100; i < 1000; i++) {
      int digit1 = i / 100;
      int digit2 = (i % 100) / 10;
      int digit3 = ((i % 100) % 10);
      bool check1 = false;
      if (digit[0] == -1)
        check1 = true;
      else if (digit[0] == digit1)
        check1 = true;
      bool check2 = false;
      if (digit[1] == -1)
        check2 = true;
      else if (digit[1] == digit2)
        check2 = true;
      bool check3 = false;
      if (digit[2] == -1)
        check3 = true;
      else if (digit[2] == digit3)
        check3 = true;
      if (check1 && check2 && check3) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
