#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
long long gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  int n, m;
  cin >> n >> m;
  int ans[n + 1][2];
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s][1] == 0) {
      ans[s][0] = c;
      ans[s][1] = 1;
    } else {
      if (ans[s][0] == c) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i < (n + 1); i++) {
    cout << ans[i][0];
  }
  cout << endl;
  return 0;
}
