#include <bits/stdc++.h>
using namespace std;
void ok(int answer) {
  cout << answer << endl;
  return;
}
void ng() {
  cout << -1 << endl;
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (m == 0) {
    if (n == 1) {
      ok(0);
    } else if (n == 2) {
      ok(10);
    } else {
      ok(100);
    }
    return 0;
  }
  int answer = -1;
  if (n == 1) {
    int one = -1;
    for (int i = 0; i < m; i++) {
      if (one == -1) {
        one = c[i];
      } else {
        ng();
        return 0;
      }
    }
    answer = one;
  } else if (n == 2) {
    int ten = -1;
    int one = -1;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && ten == -1) {
        ten = c[i];
      } else if (s[i] == 2 && one == -1) {
        one = c[i];
      } else {
        ng();
        return 0;
      }
    }
    if (ten == 0) {
      ng();
      return 0;
    }
    if (ten == -1) {
      ten = 1;
    }
    if (one == -1) {
      one = 0;
    }
    answer = (ten * 10) + one;
  } else if (n == 3) {
    int hundred = -1;
    int ten = -1;
    int one = -1;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && hundred == -1) {
        hundred = c[i];
      } else if (s[i] == 2 && ten == -1) {
        ten = c[i];
      } else if (s[i] == 3 && one == -1) {
        one = c[i];
      } else {
        ng();
        return 0;
      }
    }
    if ((hundred == 0) || (hundred == 0 && ten == 0)) {
      ng();
      return 0;
    }
    if (hundred == -1) {
      hundred = 1;
    }
    if (ten == -1) {
      ten = 1;
    }
    if (one == -1) {
      one = 0;
    }
    answer = (hundred * 100) + (ten * 10) + one;
  }
  cout << answer << endl;
  return 0;
}
