#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;
lli mod197 = 1000000007LL;
lli INF = 10000000000000;
template <typename T>
T extgcd(T a, T b, T& x, T& y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
int arr[10] = {};
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) arr[i] = -1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (arr[s - 1] != -1 && arr[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    arr[s - 1] = c;
  }
  bool f = false;
  for (int i = 0; i < n; i++) {
    if (arr[i] == -1) {
      if (f) cout << 0;
    } else {
      if (arr[i] == 0 && !f) {
        cout << -1 << endl;
        return 0;
      }
      cout << arr[i];
      f = true;
    }
  }
  cout << endl;
  return 0;
}
