#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  bool flag = true;
  int n, m;
  cin >> n >> m;
  map<int, int> sc;
  for (int i = 0; i < (int)(m); i++) {
    int ss, cc;
    cin >> ss >> cc;
    if (!sc.count(ss)) {
      sc[ss] = cc;
    } else {
      if (sc[ss] != cc) {
        cout << -1 << endl;
        flag = false;
        break;
      }
    }
    if (ss == 1) {
      if (cc == 0 && n != 1) {
        cout << -1 << endl;
        flag = false;
        break;
      }
    }
  }
  if (n == 1 && flag) {
    cout << sc.at(1) << endl;
  }
  if (flag && n == 2) {
    if (sc.count(2)) {
      if (sc.count(1)) {
        cout << 10 * sc.at(1) + sc.at(2) << endl;
      } else {
        cout << sc.at(2) << endl;
      }
    } else {
      cout << 10 * sc.at(1) << endl;
    }
  }
  if (flag && n == 3) {
    if (sc.count(3)) {
      if (sc.count(2)) {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + 10 * sc.at(2) + sc.at(3) << endl;
        } else {
          cout << 100 + 10 * sc.at(2) + sc.at(3) << endl;
        }
      } else {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + sc.at(3) << endl;
        } else {
          cout << 100 + sc.at(3) << endl;
        }
      }
    } else {
      if (sc.count(2)) {
        if (sc.count(1)) {
          cout << 100 * sc.at(1) + 10 * sc.at(2) << endl;
        } else {
          cout << 100 + 10 * sc.at(2) << endl;
        }
      } else {
        cout << 100 * sc.at(1) << endl;
      }
    }
  }
}
