#include <bits/stdc++.h>
using namespace std;
long long int bg = 998244353;
long long int power(long long int x, long long int y) {
  long long int ss = 1;
  if (y == 0) return ss;
  long long int h = (power(x, y / 2)) % bg;
  h = (h * h) % bg;
  long long int gg = (x * h) % bg;
  if (y % 2 == 1)
    return gg;
  else
    return h;
}
long long int modinv(long long int k) { return (power(k, bg - 2)) % bg; }
int main() {
  long long int i, n, m, flag = -1;
  cin >> n >> m;
  long long int arr[n];
  for (i = 0; i < n; i++) arr[i] = -1;
  for (i = 0; i < m; i++) {
    long long int a, b;
    cin >> a >> b;
    if (arr[a - 1] != -1 && b != arr[a - 1]) {
      flag = 0;
    }
    arr[a - 1] = b;
  }
  if (flag == 0) {
    cout << "-1";
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (i == 0) {
      if (arr[i] == 0) {
        cout << "-1";
        return 0;
      } else if (arr[i] == -1)
        cout << "1";
      else
        cout << arr[i];
    } else {
      if (arr[i] == -1)
        cout << "0";
      else
        cout << arr[i];
    }
  }
  return 0;
}
