#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 21;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  string ans;
  for (int i = 0; i < (n); ++i) ans += '0';
  if (n != 1) ans[0] = '1';
  sort(sc.begin(), sc.end());
  sc.erase(unique(sc.begin(), sc.end()), sc.end());
  if (sc.size() > n) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (m); ++i) {
    int s = sc[i].first, c = sc[i].second;
    ans[s] = c + '0';
  }
  for (int i = 0; i < (m); ++i) {
    int s = sc[i].first, c = sc[i].second;
    if (ans[s] != c + '0') {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
