#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  int M = 0;
  int x = 0, y = 0, z = 0;
  int s[3] = {0};
  int S[3] = {0};
  int c[9] = {0};
  int ans = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (N == 3 && s[i] == 1 && c[i] == 0) {
      cout << -1;
      return 0;
    } else if (N == 2 && s[i] == 1 && c[i] == 0) {
      cout << -1;
      return 0;
    }
    if (s[i] == 1) {
      x = c[i];
    } else if (s[i] == 2) {
      y = c[i];
    } else {
      z = c[i];
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        return 0;
      }
    }
  }
  ans = x * 100 + y * 10 + z;
  if (N == 3 && x == 0) {
    ans += 100;
  }
  if (N == 2 && y == 0) {
    ans += 10;
  }
  if (N == 1 && z == 0) {
    ans = 0;
  }
  cout << ans;
}
