#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, n[3] = {-1, -1, -1};
  bool b = true;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (n[s[i]] != -1) {
      if (n[s[i]] != c[i]) {
        b = false;
        break;
      }
    }
    n[s[i]] = c[i];
  }
  for (int i = 0; i < 3; i++) {
    if (n[i] == -1) n[i] = 0;
  }
  cout << (b ? (100 * n[0] + 10 * n[1] + n[2]) : -1);
}
