#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t, n, m, i, j, k, x = 0, y = 0, z;
  cin >> n >> m;
  map<int, int> mp1;
  vector<int> v[1000];
  int a[1000] = {100000, 100000, 100000};
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    v[l].push_back(r);
  }
  int ok1 = 0;
  for (int i = 1; i <= n; i++) {
    int ok = 0;
    if (v[i].size() > 0) {
      sort(v[i].begin(), v[i].end());
      for (int j = 0; j < v[i].size() - 1; j++) {
        if (v[i][j] != v[i][j + 1]) {
          ok = 1;
        }
      }
      if (ok == 0) {
        a[i] = v[i][0];
      }
    }
    if (ok == 1) {
      ok1 = 1;
    }
  }
  if (n == 1) {
    cout << a[1] << endl;
    return 0;
  }
  if (ok1 == 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1 && n != 1) {
      if (a[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (a[i] == 1e5) {
      a[i] = 0;
    }
  }
  if (a[1] == 0) {
    a[1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i];
  }
  cout << endl;
}
