#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  bool ok = false;
  int ans = 0;
  if (N == 1) {
    int a = c[0];
    for (int i = 0; i < M; i++) {
      if (c[i] != a) ok = true;
    }
    ans = a;
  } else if (N == 2) {
    bool c1 = false;
    bool c2 = false;
    int n1 = -1;
    int n2 = -1;
    for (int i = 0; i < M; i++) {
      int ts = s[i];
      int tc = c[i];
      if (ts == 1) {
        if (!c1) {
          n1 = tc;
          c1 = true;
          if (n1 == 0) ok = true;
        } else {
          if (n1 != tc) ok = true;
        }
      }
      if (ts == 2) {
        if (!c2) {
          n2 = tc;
          c2 = true;
        } else {
          if (n2 != tc) ok = true;
        }
      }
      if (n1 == -1) n1 = 1;
      if (n2 == -1) n2 = 0;
      ans = n1 * 10 + n2;
    }
  } else {
    bool c1 = false;
    bool c2 = false;
    bool c3 = false;
    int n1 = -1;
    int n2 = -1;
    int n3 = -1;
    for (int i = 0; i < M; i++) {
      int ts = s[i];
      int tc = c[i];
      if (ts == 1) {
        if (!c1) {
          n1 = tc;
          c1 = true;
          if (n1 == 0) ok = true;
        } else {
          if (n1 != tc) ok = true;
        }
      }
      if (ts == 2) {
        if (!c2) {
          n2 = tc;
          c2 = true;
        } else {
          if (n2 != tc) ok = true;
        }
      }
      if (ts == 3) {
        if (!c3) {
          n3 = tc;
          c3 = true;
        } else {
          if (n3 != tc) ok = true;
        }
      }
      if (n1 == -1) n1 = 1;
      if (n2 == -1) n2 = 0;
      if (n3 == -1) n3 = 0;
      ans = n1 * 100 + n2 * 10 + n3;
    }
  }
  if (ok)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
