#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  int s[5];
  int c[5];
  int b[3];
  int f = 0;
  int g = 0;
  int i = 0;
  int sum = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) g = 1;
  }
  for (i = 0; i < 3; i++) {
    b[i] = 0;
  }
  for (i = 0; i < m; i++) {
    if (b[s[i] - 1] == 0) {
      b[s[i] - 1] = c[i];
    } else {
      if (b[s[i] - 1] != c[i]) {
        f = 1;
        break;
      }
    }
  }
  if (n == 3 && b[0] == 0 && g == 1) f = 1;
  if (n == 2 && b[0] == 0 && g == 1) f = 1;
  if (f == 1) {
    cout << -1;
  } else {
    sum = b[0] * 100 + b[1] * 10 + b[2];
    if (n == 3 && sum < 100) sum = sum + 100;
    if (n == 2 && sum < 10) sum = sum + 10;
    cout << sum;
  }
}
