#include <bits/stdc++.h>
using namespace std;
unsigned getdigit(unsigned NUM) { return log10(NUM) + 1; }
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { a / gcd(a, b) * b; }
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp, C;
  vector<pair<int, int>> num(m);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s > n || (mp[s] > 0 && C[s] != c) || (s == 1 && c == 0)) {
      ok = false;
    }
    mp[s]++;
    C[s] = c;
    num[i] = make_pair(s, c);
  }
  sort(num.begin(), num.end());
  string ans = "";
  for (int i = 0; i < n; i++) {
    if (i == 0 && mp[i + 1] == 0)
      ans += to_string(1);
    else if (mp[i + 1] == 0)
      ans += to_string(0);
    else {
      ans += to_string(C[i + 1]);
    }
  }
  if (!ok)
    cout << -1 << endl;
  else if (n == 1)
    cout << 0 << endl;
  else
    cout << ans << endl;
}
