#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  long long s[M], c[M];
  for (long long(i) = 0; (i) < (M); (i)++) cin >> s[i] >> c[i];
  long long num[N];
  for (long long(i) = 0; (i) < (N); (i)++) num[i] = -1;
  bool E = false;
  for (long long(i) = 0; (i) < (M); (i)++) {
    int p = s[i] - 1;
    int q = c[i];
    if (num[p] == -1)
      num[p] = q;
    else if (num[p] == q)
      continue;
    else {
      E = true;
      break;
    }
  }
  if (E)
    cout << -1;
  else if (N != 1 && num[0] == 0)
    cout << -1;
  else {
    for (long long(i) = 0; (i) < (N); (i)++)
      cout << (num[i] == -1 ? i == 0 ? 1 : 0 : num[i]);
    cout << endl;
  }
  return 0;
}
