#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void d_err() { cerr << endl; }
template <typename H, typename... T>
void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}
long long INF = 1e16;
int inf = 1e9;
long long MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N, M;
  cin >> N >> M;
  int m[N];
  for (int i = (0); i < (N); ++i) m[i] = -1;
  bool f = true;
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (s == 0 && c == 0) {
      f = false;
      break;
    }
    if (m[s] == -1)
      m[s] = c;
    else {
      if (c != m[s]) {
        f = false;
        break;
      }
    }
  }
  if (!f)
    cout << -1 << endl;
  else {
    for (int i = (0); i < (N); ++i) {
      int o = m[i];
      if (o == -1) {
        if (i == 0 && N > 1)
          o = 1;
        else
          o = 0;
      }
      cout << o;
    }
    cout << endl;
  }
}
