#include <bits/stdc++.h>
using namespace std;
int binexp(int n) {
  if (n == 0) return 1;
  if (n == 1) return 10;
  int ans = binexp(n / 2);
  if (n % 2 == 0)
    return ans * ans;
  else
    return 10 * ans * ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  int k, c;
  int flag = 0;
  while (m--) {
    cin >> k >> c;
    k--;
    if (ans[k] == -1)
      ans[k] = c;
    else if (ans[k] != c)
      flag = 1;
  }
  if (flag == 1)
    cout << -1;
  else if (ans[0] = -1)
    ans[0] = 1;
  else if (n == 1 && ans[0] == 0)
    cout << ans[0];
  else if (n > 1 && ans[0] == 0)
    cout << -1;
  else {
    for (int i = 0; i < n; i++)
      if (ans[i] == -1) ans[i] = 0;
    int a = 0;
    for (int i = 0; i < n; i++) a += ans[i] * binexp(n - i - 1);
    cout << a;
  }
  return 0;
}
