#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, -1);
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      flag = 1;
    } else {
      if (a[s] == -1) {
        a[s] = c;
      } else {
        if (a[s] != c) {
          flag = 1;
        }
      }
    }
    if (s > n) {
      flag = 1;
    }
  }
  if (flag)
    cout << -1 << "\n";
  else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1 && (i != 1)) {
        cout << 0;
      } else if (a[i] == -1 && (i == 1))
        cout << 1;
      else
        cout << a[i];
    }
    cout << "\n";
  }
  return 0;
}
