#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e6;
const long long N = 1e3 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
long long T = 1, n, m, b, ans, y, x, c, a, used[INF], u[1001], cnt, mn = 1e18;
string s;
vector<long long> v, v1;
set<long long> st;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    st.insert(a);
    if (u[a] != 0)
      u[a] = min(u[a], b);
    else
      u[a] = b;
  }
  for (auto it : st) {
    v.push_back(it);
  }
  if (n - 1 != st.size()) return cout << "-1", 0;
  for (int i = 1; i <= n; i++) {
    if (i == v[c]) {
      cout << u[i];
      c++;
    } else {
      cout << 0;
    }
  }
}
