#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  if (N == 1) {
    bool ok = true;
    for (int i = 1; i < M; i++) {
      if (c[i] != c[i - 1]) ok = false;
    }
    if (ok)
      cout << c[0] << endl;
    else
      cout << -1 << endl;
  } else if (N == 2) {
    for (int i = 10; i < 100; i++) {
      bool ok = true;
      for (int j = 0; j < M; j++) {
        if (s[j] == 1) {
          if (i / 10 != c[j]) ok = false;
        } else if (s[j] == 2) {
          if (i % 10 != c[j]) ok = false;
        }
      }
      if (ok) {
        cout << i << endl;
        break;
      }
      　if (i == 99) cout << -1 << endl;
    }
  } else if (N == 3) {
    for (int i = 100; i < 1000; i++) {
      bool ok = true;
      for (int j = 0; j < M; j++) {
        if (s[j] == 1) {
          if (i / 100 != c[j]) ok = false;
        } else if (s[j] == 3) {
          if (i % 10 != c[j]) ok = false;
        } else if (s[j] == 2) {
          if ((i / 10) % 10 != c[j]) ok = false;
        }
      }
      if (ok) {
        cout << i << endl;
        break;
      }
      if (i == 999) cout << -1 << endl;
    }
  }
  return 0;
}
