#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct mint {
  long long x;
  mint() : x(0) {}
  mint(long long x) : x((x % MOD + MOD) % MOD) {}
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() { return mint() - *this; }
  bool operator<(const mint& a) { return x < a.x; }
  bool operator>(const mint& a) { return x > a.x; }
  bool operator<=(const mint& a) { return x <= a.x; }
  bool operator>=(const mint& a) { return x >= a.x; }
  bool operator==(const mint& a) { return x == a.x; }
  bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}
void solve(istream& cin, ostream& cout) {
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  int ans = 0;
  for (int i = (0); i <= (M - 1); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      ans = -1;
      break;
    }
    if (d[s - 1] == -1)
      d[s - 1] = c;
    else if (d[s - 1] == c)
      continue;
    else {
      ans = -1;
      break;
    }
  }
  if (ans != -1) {
    for (int i = (0); i <= (N - 1); i++) {
      cout << d[i] << '\n';
      if (d[i] != -1) ans += d[i] * pow(10, N - i - 1);
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  solve(cin, cout);
}
