#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
signed main(void) {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  ;
  unordered_map<int, int> map, count;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    count[a]++;
    if (count[a] == 1) {
      map[a] = b;
    } else {
      if (map[a] != b) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  if (count[1] >= 1 && map[1] == 0) {
    cout << -1 << '\n';
    return 0;
  } else {
    for (int i = 1; i <= N; i++) {
      if (i == 1) {
        if (map[i] == 0) {
          cout << 1;
        } else {
          cout << map[i];
        }
      } else {
        if (count[i] == 0)
          cout << 0;
        else
          cout << map[i];
      }
    }
  }
  return 0;
}
