#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int flag = 0;
  int A = 0, B = 0, C = 0;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1) {
      if (A == 0) {
        A = c[i];
      } else if (A != 0 and A != c[i]) {
        flag++;
      }
    }
    if (s[i] == 2) {
      if (B == 0) {
        B = c[i];
      } else if (B != 0 and B != c[i]) {
        flag++;
      }
    }
    if (s[i] == 3) {
      if (C == 0) {
        C = c[i];
      } else if (C != 0 and C != c[i]) {
        flag++;
      }
    }
  }
  if (m = 0) {
    if (n = 3) {
      cout << 100;
    }
    if (n = 2) {
      cout << 10;
    }
    if (n = 1) {
      cout << 0;
    }
  }
  if (flag != 0) {
    cout << -1;
  }
  if (flag == 0) {
    if (n == 3) {
      if (A == 0) {
        cout << -1;
      } else {
        cout << A * 100 + B * 10 + C;
      }
      if (n == 2) {
        if (A == 0) {
          cout << -1;
        }
        if (C != 0) {
          cout << -1;
        } else {
          cout << A * 10 + B;
        }
      }
      if (n == 1) {
        if (A == 0) {
          cout << -1;
        }
        if (C != 0 or B != 0) {
          cout << -1;
        } else {
          cout << A;
        }
      }
    }
  }
}
