#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[3];
  int c[9];
  map<int, int> q;
  bool j = true;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> s[i] >> t;
    if (q[s[i] - 1] == 0) {
      q[s[i] - 1] = t;
      c[i] = t;
    } else {
      if (q[s[i] - 1] != t) j = false;
    }
  }
  if (j == false) {
    cout << "-1" << endl;
    return 0;
  }
  int ans_a[3] = {1, 0, 0};
  int ans_b[2] = {1, 0};
  int ans_c[2] = {0, 0};
  int ans = 0;
  if (n == 3) {
    for (int i = 0; i < m; i++) {
      ans_a[s[i] - 1] = c[i];
    }
  }
  if (n == 2) {
    for (int i = 0; i < m; i++) {
      ans_b[s[i] - 1] = c[i];
    }
  }
  if (n == 1) {
    for (int i = 0; i < m; i++) {
      ans_c[s[i] - 1] = c[i];
    }
  }
  if (n > 1) {
    for (int i = 0; i < m; i++) {
      if ((s[i] == 1) && (c[i] == 0)) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (n == 3) {
    ans = ans_a[0] * 100 + ans_a[1] * 10 + ans_a[2];
  } else if (n == 2) {
    ans = ans_b[0] * 10 + ans_b[1];
  } else if (n == 1) {
    ans = ans_c[0];
  }
  cout << ans << endl;
  return 0;
}
