#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int p[3];
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(3); i++) p[i] = -1;
  bool ok = true;
  for (int i = 0; i < (int)(m); i++) {
    bool okk = false;
    int a, b;
    cin >> a;
    if (p[a - 1] != -1) {
      b = p[a - 1];
      okk = true;
    }
    cin >> p[a - 1];
    if (okk) {
      if (b != p[a - 1]) {
        ok = false;
      }
    }
  }
  if (n != 1 && p[0] == 0) ok = false;
  int res = 0;
  if (ok) {
    if (n == 3) {
      if (p[2] != -1) res += p[2];
      if (p[1] != -1) res += p[1] * 10;
      if (p[0] != -1)
        res += p[0] * 100;
      else
        res += 100;
    }
    if (n == 2) {
      if (p[1] != -1) res += p[1];
      if (p[0] != -1)
        res += p[0] * 10;
      else
        res += 10;
    }
    if (n == 1) {
      if (p[0] != -1) res += p[0] * 10;
    }
  }
  if (ok)
    cout << res << endl;
  else
    cout << "-1" << endl;
}
