#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[6], c[6], a[3];
  bool tes = 1;
  for (int i = 0; i < 3; i++) {
    a[i] = -1;
  }
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
    if (a[s[i] - 1] == -1) {
      a[s[i] - 1] = c[i];
    } else {
      if (a[s[i] - 1] != c[i]) {
        tes = 0;
      }
    }
    if (s[i] == 1 && c[i] == 0 && n > 1) {
      tes = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 2 && c[i] == 0 && a[0] == -1) {
      tes = 0;
    }
  }
  if (tes == 0) {
    cout << -1 << endl;
  } else if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else if (n == 2) {
      cout << 10 << endl;
    } else if (n == 3) {
      cout << 100 << endl;
    }
  } else {
    for (int i = 0; i < 3; i++) {
      if (a[i] == -1) {
        a[i] = 0;
      }
    }
    if (n == 3) {
      int ans;
      ans = a[0] * 100 + a[1] * 10 + a[2];
      cout << ans << endl;
    } else if (n == 2) {
      int ans;
      ans = a[0] * 10 + a[1];
      cout << ans << endl;
    } else {
      cout << a[0] << endl;
    }
  }
  return 0;
}
