#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double PI = acos(-1);
static const int INF = 1e9 + 7;
template <typename T>
void view(T e) {
  cout << e << endl;
}
template <typename T>
void view(const vector<T>& v) {
  for (const auto& e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T>
void view(const vector<vector<T> >& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) {
    int sx, cx;
    cin >> sx >> cx;
    sx--;
    s[i] = sx;
    c[i] = cx;
  };
  ;
  vector<int> a(n, -1);
  ;
  for (int i = 0; i < (m); ++i) {
    if ((s[i] == 0) && (c[i] == 0)) {
      cout << -1 << endl;
      return 0;
    }
    if ((a[s[i]] != -1) && (a[s[i]] != c[i])) {
      cout << -1 << endl;
      return 0;
    }
    a[s[i]] = c[i];
    ;
  }
  for (int i = 0; i < (n); ++i) {
    if (a[i] == -1) {
      if (i == 0)
        a[i] = 1;
      else
        a[i] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans *= 10;
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
