#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
using V = vector<T>;
using Graph = vector<vector<int>>;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
signed main() {
  int n, m;
  cin >> n >> m;
  if (m > 0) {
    V<int> s(m), c(m);
    for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
    V<set<int>> st(n);
    for (int i = 0; i < m; i++) st[s[i] - 1].insert(c[i]);
    bool ok = 1;
    for (int i = 0; i < n; i++) {
      if (st[i].size() > 1) ok = 0;
    }
    string t;
    if (ok) {
      if (n == 1) {
        if (st[0].size() == 0)
          t = "0";
        else
          t = to_string(*begin(st[0]));
      } else {
        for (int i = 0; i < n; i++) {
          if (i == 0 && !st[i].empty() && *begin(st[i]) == 0)
            ok = 0;
          else if (i == 0) {
            if (st[i].size() == 0)
              t += '1';
            else
              t += to_string(*begin(st[i]));
          } else {
            if (st[i].size() == 0)
              t += '0';
            else
              t += to_string(*begin(st[i]));
          }
        }
      }
    }
    if (ok)
      cout << t << endl;
    else
      cout << -1 << endl;
  } else {
    string t;
    if (n == 1)
      t = "0";
    else {
      t += '1';
      for (int i = 0; i < n - 1; i++) t += '0';
    }
  }
}
