import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;

public final class Main {
  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  }
} import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io public final class Main {
  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  }
} Main public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  } main {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  } try (IO io = new IO(System.in, System.out)) {
      execute(io);
    } {
      execute(io);
    } IO io = new IO(System.in, System.out) IO io = new IO(System.in, System.out) new IO(System.in, System.out) execute(io) execute io final String[] args args private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  } execute {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  } int k = io.nextInt(); k io.nextInt() io.nextInt io int n = io.nextInt(); n io.nextInt() io.nextInt io int[] a = io.nextInt(n); a io.nextInt(n) io.nextInt io n int max = k - a[n - 1] + a[0]; max k - a[n - 1] + a[0] k - a[n - 1] k a[n - 1] a n - 1 n 1 a[0] a 0 for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    } {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    } int d = a[i] - a[i - 1]; d a[i] - a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 if (d > max) {
        max = d;
      } d > max d max {
        max = d;
      } max = d max d io.println(k - max) io.println io k - max k max final IO io io public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  } M public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    } gcd {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    } int tmp; tmp while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      } b != 0 b 0 {
        tmp = a;
        a = b;
        b = tmp % b;
      } tmp = a tmp a a = b a b b = tmp % b b tmp % b tmp b return a; a int a a int b b public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    } gcd {
      return gcd(gcd(a, b), c);
    } return gcd(gcd(a, b), c); gcd(gcd(a, b), c) gcd gcd(a, b) gcd a b c final int a a final int b b final int c c public static int min(final int a, final int b) {
      return a > b ? b : a;
    } min {
      return a > b ? b : a;
    } return a > b ? b : a; a > b ? b : a a > b a b b a final int a a final int b b public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    } min {
      return min(min(a, b), min(b, c));
    } return min(min(a, b), min(b, c)); min(min(a, b), min(b, c)) min min(a, b) min a b min(b, c) min b c final int a a final int b b final int c c public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  } IO private final InputStream in; in private final BufferedOutputStream out; out private static final int BUFSIZE = 1 << 20; BUFSIZE 1 << 20 1 20 private final byte[] buf = new byte[BUFSIZE]; buf new byte[BUFSIZE] BUFSIZE private int index = 0; index 0 private int total = 0; total 0 private static final byte[] SP = new byte[] { 0x20 }; SP new byte[] { 0x20 } private static final byte[] CRLF = System.lineSeparator().getBytes(); CRLF System.lineSeparator().getBytes() System.lineSeparator().getBytes System.lineSeparator() System.lineSeparator System public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    } IO {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    } this.in = in this.in this this.in in this.out = new BufferedOutputStream(out) this.out this this.out new BufferedOutputStream(out) final InputStream in in final PrintStream out out @Override
    public void close() throws IOException {
      in.close();
      out.close();
    } close {
      in.close();
      out.close();
    } in.close() in.close in out.close() out.close out private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    } scan {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    } if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      } index >= total index total {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      } index = 0 index 0 total = in.read(buf) total in.read(buf) in.read in buf if (total <= 0)
          return -1; total <= 0 total 0 return -1; -1 1 return buf[index++]; buf[index++] buf index++ index public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    } next {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    } int c; c for (c = scan(); c <= 32; c = scan()); c = scan(); c = scan() c scan() scan c <= 32 c 32 c = scan() c = scan() c scan() scan ; StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (; c > 32; c = scan())
        sb.append((char) c); ; c > 32 c 32 c = scan() c = scan() c scan() scan sb.append((char) c); sb.append((char) c) sb.append sb (char) c return sb.toString(); sb.toString() sb.toString sb public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    } nextInt {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    } int c c val = 0; val 0 for (c = scan(); c <= 32; c = scan()); c = scan(); c = scan() c scan() scan c <= 32 c 32 c = scan() c = scan() c scan() scan ; boolean neg = c == '-'; neg c == '-' c '-' if (c == '-' || c == '+')
        c = scan(); c == '-' || c == '+' c == '-' c '-' c == '+' c '+' c = scan() c scan() scan for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15); ; c >= '0' && c <= '9' c >= '0' c '0' c <= '9' c '9' c = scan() c = scan() c scan() scan val = (val << 3) + (val << 1) + (c & 15); val = (val << 3) + (val << 1) + (c & 15) val (val << 3) + (val << 1) + (c & 15) (val << 3) + (val << 1) + (c & 15) (val << 3) val 3 (val << 1) val 1 (c & 15) c 15 return neg ? -val : val; neg ? -val : val neg -val val val public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    } nextInt {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    } final int[] result = new int[n]; result new int[n] n for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        result[i] = nextInt();
      } {
        result[i] = nextInt();
      } result[i] = nextInt() result[i] result i nextInt() nextInt return result; result final int n n public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    } nextLong {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    } int c; c long val = 0; val 0 for (c = scan(); c <= 32; c = scan()); c = scan(); c = scan() c scan() scan c <= 32 c 32 c = scan() c = scan() c scan() scan ; boolean neg = c == '-'; neg c == '-' c '-' if (c == '-' || c == '+')
        c = scan(); c == '-' || c == '+' c == '-' c '-' c == '+' c '+' c = scan() c scan() scan for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15); ; c >= '0' && c <= '9' c >= '0' c '0' c <= '9' c '9' c = scan() c = scan() c scan() scan val = (val << 3) + (val << 1) + (c & 15); val = (val << 3) + (val << 1) + (c & 15) val (val << 3) + (val << 1) + (c & 15) (val << 3) + (val << 1) + (c & 15) (val << 3) val 3 (val << 1) val 1 (c & 15) c 15 return neg ? -val : val; neg ? -val : val neg -val val val public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    } nextLong {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    } final long[] result = new long[n]; result new long[n] n for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        result[i] = nextLong();
      } {
        result[i] = nextLong();
      } result[i] = nextLong() result[i] result i nextLong() nextLong return result; result final int n n public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    } print {
      out.write(a.toString().getBytes());
    } out.write(a.toString().getBytes()) out.write out a.toString().getBytes() a.toString().getBytes a.toString() a.toString a final Object a a public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    } printsp {
      out.write(a.toString().getBytes());
      out.write(SP);
    } out.write(a.toString().getBytes()) out.write out a.toString().getBytes() a.toString().getBytes a.toString() a.toString a out.write(SP) out.write out SP final Object a a public void println() throws IOException {
      out.write(CRLF);
    } println {
      out.write(CRLF);
    } out.write(CRLF) out.write out CRLF public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    } println {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    } out.write(a.toString().getBytes()) out.write out a.toString().getBytes() a.toString().getBytes a.toString() a.toString a out.write(CRLF) out.write out CRLF final Object a a public void flush() throws IOException {
      out.flush();
    } flush {
      out.flush();
    } out.flush() out.flush out AutoCloseable public final class Main {
  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  }
} public final class Main {
  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  }
} Main
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;

public final class Main {
  public static void main(final String[] args) throws Exception {
    try (IO io = new IO(System.in, System.out)) {
      execute(io);
    }
  }

  private static void execute(final IO io) throws Exception {
    int k = io.nextInt();
    int n = io.nextInt();
    int[] a = io.nextInt(n);
    int max = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
      int d = a[i] - a[i - 1];
      if (d > max) {
        max = d;
      }
    }
    io.println(k - max);
  }

  public static final class M {
    public static int gcd(int a, int b) {
      int tmp;
      while (b != 0) {
        tmp = a;
        a = b;
        b = tmp % b;
      }
      return a;
    }

    public static int gcd(final int a, final int b, final int c) {
      return gcd(gcd(a, b), c);
    }

    public static int min(final int a, final int b) {
      return a > b ? b : a;
    }

    public static int min(final int a, final int b, final int c) {
      return min(min(a, b), min(b, c));
    }
  }

  public static final class IO implements AutoCloseable {
    private final InputStream in;
    private final BufferedOutputStream out;
    private static final int BUFSIZE = 1 << 20;
    private final byte[] buf = new byte[BUFSIZE];
    private int index = 0;
    private int total = 0;
    public IO(final InputStream in, final PrintStream out) throws IOException {
      this.in = in;
      this.out = new BufferedOutputStream(out);
    }

    @Override
    public void close() throws IOException {
      in.close();
      out.close();
    }

    private int scan() throws IOException {
      if (index >= total) {
        index = 0;
        total = in.read(buf);
        if (total <= 0)
          return -1;
      }
      return buf[index++];
    }

    public String next() throws IOException {
      int c;
      for (c = scan(); c <= 32; c = scan());
      StringBuilder sb = new StringBuilder();
      for (; c > 32; c = scan())
        sb.append((char) c);
      return sb.toString();
    }

    public int nextInt() throws IOException {
      int c, val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public int[] nextInt(final int n) throws IOException {
      final int[] result = new int[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextInt();
      }
      return result;
    }

    public long nextLong() throws IOException {
      int c;
      long val = 0;
      for (c = scan(); c <= 32; c = scan());
      boolean neg = c == '-';
      if (c == '-' || c == '+')
        c = scan();
      for (; c >= '0' && c <= '9'; c = scan())
        val = (val << 3) + (val << 1) + (c & 15);
      return neg ? -val : val;
    }

    public long[] nextLong(final int n) throws IOException {
      final long[] result = new long[n];
      for (int i = 0; i < n; i++) {
        result[i] = nextLong();
      }
      return result;
    }

    public void print(final Object a) throws IOException {
      out.write(a.toString().getBytes());
    }

    private static final byte[] SP = new byte[] { 0x20 };
    public void printsp(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(SP);
    }

    private static final byte[] CRLF = System.lineSeparator().getBytes();
    public void println() throws IOException {
      out.write(CRLF);
    }

    public void println(final Object a) throws IOException {
      out.write(a.toString().getBytes());
      out.write(CRLF);
    }

    public void flush() throws IOException {
      out.flush();
    }
  }
}
