#include <bits/stdc++.h>
using namespace std;
const long long N = 500030;
const long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    v[i] = -1;
  bool b = false;
  vector<pair<int, int> > vp;
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    int x, y;
    cin >> x >> y;
    vp.push_back({x, y});
  }
  sort(vp.begin(), vp.end());
  if (n == 1) {
    for (__typeof(m) i = (1) - ((1) > (m)); i != (m) - ((1) > (m));
         i += 1 - 2 * ((1) > (m))) {
      if (vp[i].second != vp[i - 1].second) {
        cout << "-1";
        return 0;
      }
    }
    cout << vp[0].second;
    return 0;
  } else {
    for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
         i += 1 - 2 * ((0) > (m))) {
      int x = vp[i].first;
      int y = vp[i].second;
      if (x == 1) {
        if (y <= 0) b = true;
        if (v[x - 1] == -1 || v[x - 1] == y)
          v[x - 1] = y;
        else
          b = true;
      } else {
        if (v[x - 1] == -1 || v[x - 1] == y)
          v[x - 1] = y;
        else
          b = true;
      }
    }
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      if (!i) {
        if (v[i] == -1) v[i] = 1;
        if (v[i] <= 0) b = true;
      } else {
        if (v[i] == -1) v[i] = 0;
      }
    }
    if (b)
      cout << "-1";
    else {
      for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
           i += 1 - 2 * ((0) > (n)))
        cout << v[i];
    }
  }
}
