#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (int i = 0, i_len = (m); i < i_len; ++i)
    cin >> sc[i].first >> sc[i].second;
  vector<int> a(n);
  for (int i = 0, i_len = (n); i < i_len; ++i) a[i] = -1;
  for (int i = 0, i_len = (m); i < i_len; ++i) {
    if (a[sc[i].first - 1] == -1)
      a[sc[i].first - 1] = sc[i].second;
    else if (a[sc[i].first - 1] != sc[i].second) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (n == 1 && a[0] <= 0)
    cout << 0 << "\n";
  else {
    bool flg2 = false;
    for (int i = 0, i_len = (n); i < i_len; ++i) {
      if (a[i] != -1) {
        if (!flg2 && a[i] == 0) {
          cout << -1 << "\n";
          return 0;
        }
        flg2 = true;
      }
    }
    bool flg = false;
    for (int i = 0, i_len = (n); i < i_len; ++i) {
      if (a[i] == -1) {
        if (!flg)
          cout << 1;
        else
          cout << 0;
      } else {
        cout << a[i];
        flg = true;
      }
    }
    cout << "\n";
  }
  return 0;
}
