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