#include <bits/stdc++.h>
using namespace std;
const int INF = 1e6;
const int MAX = 1e5 + 10;
long long llipower(long long x, long long y) {
  long long res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long llipowerp(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (!a) return b;
  return gcd(b % a, a);
}
long long binarySearch(vector<int> arr, int l, int r, int x) {
  if (r >= l) {
    long long mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
template <typename T>
void printvec(vector<T> inp) {
  for (int i = 0; i < inp.size(); i++) {
    cout << inp[i] << " ";
  }
  cout << "\n";
}
template <typename T>
T ceildiv(T x, T y) {
  return 1 + ((x - 1) / y);
}
long long modInverse(long long a, long long m) {
  long long g = gcd(a, m);
  if (g != 1)
    return -1;
  else
    return llipowerp(a, m - 2, m);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> num(n, -1);
  bool con = true;
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0 && n > 1) {
      con = false;
      break;
    } else {
      if (num[s[i] - 1] == -1)
        num[s[i] - 1] = c[i];
      else {
        if (num[s[i] - 1] != c[i]) {
          con = false;
          break;
        }
      }
    }
  }
  if (con) {
    for (int i = 0; i < n; i++) {
      if (num[i] != -1)
        cout << num[i];
      else {
        if (i != 0)
          cout << 0;
        else {
          if (n == 0)
            cout << 0;
          else
            cout << 1;
        }
      }
    }
    cout << "\n";
  } else
    cout << -1 << "\n";
}
