#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
struct Union {
  vector<int> par;
  Union(int a) { par = vector<int>(a, -1); }
  int find(int a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(int a, int b) { return (find(a) == find(b)); }
  int size(int a) { return -par[find(a)]; }
  void unite(int a, int b) {
    int c = find(a), d = find(b);
    if (c == d) return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[n], t[n], u[n];
  for (ll i = 0; i < n; ++i) {
    u[i] = -1;
  }
  for (ll i = 0; i < m; ++i) {
    cin >> s[i] >> t[i];
    if ((n > 1 && s[i] == 1 && t[i] == 0) ||
        (u[s[i] - 1] != -1 && t[i] != u[s[i] - 1])) {
      cout << -1;
      return 0;
    } else
      u[s[i] - 1] = t[i];
  }
  for (ll i = 0; i < n; ++i) {
    if (u[i] = -1) cout << 0;
    cout << u[i];
  }
}
