#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> mp;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (mp.find(x) != mp.end()) {
      if (mp[x] != y) {
        cout << -1;
        return 0;
      }
    } else
      mp[x] = y;
    if (x == 1 && y == 0) {
      if (n == 1) {
        cout << 0;
        return 0;
      } else {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (mp.find(i) == mp.end()) {
      if (i == 1)
        cout << 1;
      else
        cout << 0;
    } else
      cout << mp[i];
  }
  return 0;
}
