#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ansi = -1;
  if (n == 1) {
    for (int i = 0; i < m; i++) {
      int s, c;
      cin >> s >> c;
      ansi = c;
    }
  } else if (n == 2) {
    vector<vector<int>> vec(n);
    for (int i = 0; i < m; i++) {
      int s, c;
      cin >> s >> c;
      if (s == 1 and c == 0) {
        cout << ansi << endl;
        return 0;
      }
      if (!vec[s - 1].empty()) {
        if (vec[s - 1][0] != c) {
          cout << ansi << endl;
          return 0;
        }
      } else {
        vec[s - 1].push_back(c);
      }
    }
    string ans = "00";
    for (int i = 0; i < 2; i++) {
      for (int v : vec[i]) {
        ans.replace(i, 1, to_string(v));
      }
    }
    ansi = stoi(ans);
  } else if (n == 3) {
    vector<vector<int>> vec(n);
    for (int i = 0; i < m; i++) {
      int s, c;
      cin >> s >> c;
      if (s == 1 and c == 0) {
        cout << ansi << endl;
        return 0;
      }
      if (!vec[s - 1].empty()) {
        if (vec[s - 1][0] != c) {
          cout << ansi << endl;
          return 0;
        }
      } else {
        vec[s - 1].push_back(c);
      }
    }
    string ans = "000";
    for (int i = 0; i < 3; i++) {
      for (int v : vec[i]) {
        ans.replace(i, 1, to_string(v));
      }
    }
    ansi = stoi(ans);
  }
  cout << ansi << endl;
}
